我已经尝试并组合了一些脚本来删除行,但这并没有重置计数器。帮助重置响应将不胜感激。
我的副本表功能,并删除所有行功能,但计数器仍然存在,显示58个响应。
我使用触发器设置每天发生的复制和删除功能。 (表格网址不包括“docs.google.com ...”0AvTM4SfinH2NdGp1MHdzWms2QnpUMnFiMHJXd1dlV1E& usp)这是我目前所拥有的:
function CopySheet() {
var sh = SpreadsheetApp.getActiveSpreadsheet();
var ss = sh.getSheets()[0];// here I chose to always get the first sheet in the spreadsheet
var inputRange = ss.getRange(1,1,ss.getLastRow(),7);
var data = inputRange.getValues();
var newData = [];
newData.push(['Timestamp','Full Name?','Email?','RAG']);
for(var n=1;n<data.length;++n){ // skip headers by starting at 1
for(var c=0;c<7;c=c+3){
var row = [];
if(c==0){row.push(data[n][0]) ; c++}else{row.push('')};
row.push(data[n][c])
row.push(data[n][c+1]);
row.push(data[n][c+1+1]);//Keep adding a new row and +1 for each extra column
newData.push(row);
}
}
//This next bit creates a copy of the sheet. I would rather a spreadsheet copy but could only get document copy to work
sh.insertSheet().getRange(1,1,newData.length,newData[0].length).setValues(newData);
var doc = DocumentApp.create('Responses document'); // create document
var file = DocsList.getFileById(doc.getId());
file.removeFromFolder(DocsList.getRootFolder());
file.addToFolder(DocsList.getFolder("Folder 1"));
var table = doc.getBody().appendTable(newData); // create table in a separate process so I can set the style below
var style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER; // this one has no effect
style[DocumentApp.Attribute.FONT_FAMILY] = DocumentApp.FontFamily.ARIAL;
style[DocumentApp.Attribute.FONT_SIZE] = 10;
style[DocumentApp.Attribute.FOREGROUND_COLOR] = '#0000ff';
style[DocumentApp.Attribute.BORDER_COLOR] = '#dddddd' ;
table.setAttributes(style);
}
//This section deletes the sheet, leaving the headers; "function deleteAllResponses()" at the bottom should reset counter but does not work
function DeleteSheet() {
SpreadsheetApp.flush();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var datarange = sheet.getDataRange();
var lastrow = datarange.getLastRow();
var values = datarange.getValues();// get all data in a 2D array
for (i=lastrow;i>=2;i--) {
var tempdate = values[i-1][2]; // arrays are 0 indexed so row1 = values[0] and col3 = [2], If I add more columns I need to up this number
{
sheet.deleteRow(i);
function deleteAllResponses() {}
}
}
}
答案 0 :(得分:2)
如果您的意思是表格中显示的反应答案:
一种选择可能是deleteAllResponses()使用Class Form(仔细阅读文档)。
最小的实现可以是:
/* CODE FOR DEMONSTRATION PURPOSES */
function deleteAllResponses() {
var form, urlForm = SpreadsheetApp.getActiveSpreadsheet().getFormUrl();
if (urlForm) {
form = FormApp.openByUrl(urlForm);
if (form) form.deleteAllResponses();
}
}
答案 1 :(得分:0)
@ user2847142,@ brian-tompsett,@ wchiquito
新版Google表单允许您在不需要脚本的情况下从Google表单中删除个别回复。
现在有一种比@wchiquito给出的答案更简单的方法。
- 现在可以在新版Google表单
上使用Google于2016年2月10日发布公告。(googleappsupdates.blogspot.com/2016/02/new-google-forms-now-default-option.html)
如何删除所有回复:
如何删除个别回复:
要删除个别回复,请单击“回复”标签,然后选择“个人”。找到要删除的记录,然后单击垃圾桶图标以删除该个人响应 这也会重置计数器 的然而即可。响应/不会从连接到表单电子表格中删除。您必须手动删除那些(或使用脚本)。