简体   繁体   English

使用Google Apps脚本转换表单提交

[英]Using Google Apps script to convert form submissions

I'm new to Google Apps , and I'm having much difficulty reformatting my data. 我是Google Apps新手,在重新格式化数据方面遇到很多困难。

I built a form that outputs into Google Spreadsheet. 我建立了一个输出到Google Spreadsheet的表单。 The form asks 6 questions, and it asks that set of 6 questions 5x. 该表格提出了6个问题,并以5倍的比例提出了这6个问题。 Currently, the output shows 30 columns of data. 当前,输出显示30列数据。 I want to build a Google Apps Script that can reformat that into a single list of data, so each submission will convert to 5 rows of data that is 6 columns wide instead of 1 row of data that is 30 columns wide. 我想构建一个可以将其重新格式化为单个数据列表的Google Apps脚本,因此每个提交都将转换为5行6列宽的数据,而不是1行30列宽的数据。

As an added tweak, Column A shows the date of submission, and I would like it to repeat this for each row of data from that submission. 作为一项附加调整,A列显示了提交日期,我希望它对该提交的每一行数据重复此操作。 Also, each submission can have up to 5 entries (of 6 pieces of data each), but it can also have just 1,2,3 or 4. 此外,每个提交最多可以有5个条目(每个条目有6条数据),但也只能有1,2,3或4。

Here is the output I'm working with: 这是我正在使用的输出:

https://docs.google.com/spreadsheet/ccc?key=0AltfQKymTKF2dGRrMU50ZkU3MGhIUHlvSFdBMDd2MWc&rm=full#gid=0 https://docs.google.com/spreadsheet/ccc?key=0AltfQKymTKF2dGRrMU50ZkU3MGhIUHlvSFdBMDd2MWc&rm=full#gid=0

I think the formula should say something like: 我认为公式应该像这样:

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.

Please help me if you have ideas! 如果您有想法请帮助我!

Data coming from forms are also available as variables when using an "on form submit' trigger, see doc here about Spreadsheet Form Submit Events 使用“在表单提交”触发器时,来自表单的数据也可用作变量, 有关电子表格表单提交事件的信息 ,请参见此处的文档

you should use these variable to build the spreadsheet arrangement you want in a second sheet while leaving the 30 columns one as it is... 您应该使用这些变量在第二张工作表中构建所需的电子表格排列,同时将30列保留为原样...

The best approach would probably be to build a 2D array with the appropriate data and to write it at once in this sheet (could be in another spreadsheet as well... ) 最好的方法可能是用适当的数据构建一个2D数组,并立即在此工作表中写入它(也可以在另一个电子表格中...)

this should be quite easy to setup by pushing data in an array 5 by 5 if the answer is not empty 如果答案不为空,则通过将数组中的数据乘以5乘5来进行设置应该非常容易

something like this (not tested) 像这样的东西(未经测试)

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
}

EDIT : I mixed up 5 and 6, I changed the script to handle 5 rows of 6 answers... sorry if you saw first version ;-) 编辑:我混合了5和6,我更改了脚本以处理5行的6个答案...对不起,如果您看到第一个版本;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM