我想建立一个谷歌应用程序脚本,可以重新格式化成一个单一的数据列表,所以每次提交将转换为5行数据,是6列宽,而不是1行数据,是30列宽。
作为一个添加的调整,列A显示了提交日期,我希望它对该提交的每一行数据重复此日期。此外,每次提交最多可以有5个条目(每个条目包含6条数据),但也可以只有1、2、3或4个条目。
下面是我正在使用的输出:
我认为公式应该是这样的:
Look at Column H
Find first instance where cell is not blank
Copy that and 6 cells over
Paste
Set the original copied cells to blank
i + 1
repeat
then repeat the entire process in Column M
then repeat the entire process in Column T
etc.如果你有想法,请帮助我!
发布于 2013-05-09 02:14:07
当使用"on form submit“触发器时,来自表单的数据也可以作为变量使用,请参见doc here about Spreadsheet Form Submit Events
您应该使用这些变量在第二个工作表中构建您想要的电子表格排列,同时保留30列...
最好的方法可能是使用适当的数据构建一个2D数组,并立即将其写入此工作表中(也可以在另一个电子表格中...)
如果答案不为空,则通过将数组5x5中的数据推送到数组中,这应该很容易设置
类似这样的东西(未测试)
function formSubmit(e) {
var data = []
for(n=0;n<5;++n){
var row = []
if(e.values[3+n]!=''){ // if first element of serie n is not empty
for(c=0;c<6;++c){
row.push(e.values[3+n+c]);// build row n with 6 colums (0 to 5)
}
}else{continue}
data.push(row);// add row n to data (0 to 4)
}
SpreadsheetApp.getActiveSpreadsheet().getSheets()[1].getRange(1,1,data.length,data[0].length).setValues(data);// write data to sheet #2
}编辑:我混淆了5和6,我更改了脚本来处理5行6个答案...如果您看到第一个版本,很抱歉;-)
https://stackoverflow.com/questions/16410990
复制相似问题