简体   繁体   English

如何将大量的表单响应表合并到一个主表中。 (Google表格)

[英]How to merge a large number of form response sheets into one master sheet. (Google Sheets)

I have a spreadsheet in which I have the form response sheets from a large number of forms (quizzes). 我有一个电子表格,其中有大量表单(测验)的表单响应表。 As all the forms contain the same format, number and order of questions I want to collect them all into one sheet. 由于所有表格都包含相同的格式,数量和问题顺序,因此我想将它们全部收集到一张纸中。

I know this can be done using the query({sheet1!range,sheet2!range...}) But the size of this query would be huge (have over 25 forms!) and it would require me to fiddle around with this formula every time I add a new form. 我知道可以使用query({sheet1!range,sheet2!range ...})来完成此操作,但是此查询的大小非常大(有25种以上的表格!),这需要我弄乱这个公式每次我添加新表格。

What i initially investigated was creating a list of sheets in a range and then tried to get arrayformula query to run through that list using indirect. 我最初研究的是在一个范围内创建一个工作表列表,然后尝试使用间接查询来获取arrayformula查询以遍历该列表。 This however did not work and after asking on this forum have been told that that cannot be done. 但是,此操作无效,并在此论坛上询问后被告知无法完成。

I was advised to look into scripts and have spent all weekend trying to find a script that can do this. 建议我研究脚本,并花了整个周末的时间试图找到可以做到这一点的脚本。 I have however failed. 但是我失败了。

I need the script to copy the last row of a form response sheet to the bottom of a master sheet. 我需要脚本将表单响应表的最后一行复制到主表的底部。 I would like the script to do this to all response sheets (I have a naming format for sheets that would allow the script to easily see which sheets to incorporate). 我希望脚本对所有响应表执行此操作(我为表提供了一种命名格式,该格式可以使脚本轻松查看要合并的表)。 I would imagine I need to use the onSubmit() function but not sure. 我想我需要使用onSubmit()函数,但不确定。

Overview 总览

I don't think that using a on submit trigger is a good idea because there are several forms involved and a large number of responses. 我认为使用“提交时触发”不是一个好主意,因为涉及多种形式和大量响应。 By the other hand could be conflicts if several responses are submitted very close. 另一方面,如果非常接近地提交多个答复,则可能会产生冲突。 IMHO a better approach is to run the script by demand (manually) or by using a time-driven trigger . 恕我直言,更好的方法是按需(手动)或使用时间驱动的触发器来运行脚本。

As Google Apps Script execution time should not exceed six minutes 1 , instead of checking each sheet for new responses I think that a better approach is to clear the master sheet and append all the sheet responses at once. 由于Google Apps Script的执行时间不应超过六分钟1 ,因此我认为最好不要清除母版工作表并立即附加所有工作表响应,而不是检查每个工作表是否有新的响应。 This could work if there will no be notes, comments, custom formats, data validations or data changes applied directly on the master sheet. 如果没有注释,注释,自定义格式,数据验证或数据更改直接应用于母版表,则此方法可行。

Script 脚本

Below is a script that joins the content of form responses sheets that are in the same spreadsheet to a sheet named 'Master'. 下面是一个脚本,用于将同一电子表格中的表单响应工作表的内容连接到名为“主”的工作表。 It could be easily adapted, I think. 我认为,它很容易适应。

It's assumed that the spreadsheet only contains form responses sheets and the 'Master' sheet. 假定电子表格仅包含表单响应表和“主”表。

/**
 * Joins the data from form responses sheets on a master responses sheet.
 * Assumes that the master sheet has the form response headers and 
 * that there aren't extra columns.
 */

function joinSheetsData() {
  // Initialize loop variables
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets();
  var masterName = 'Master';                             // Change this.
  var masterSheet = ss.getSheetByName(masterName);
  var headers = [masterSheet.getDataRange().getValues()[0]];
  var masterdata = [];

  // Loop to append form responses from all response sheets to one array. 
  for(var i = 0; i < sheets.length; i++){ 
    if(sheets[i].getName() != masterSheet.getName()){
      var data = sheets[i].getDataRange().getValues();
      data.splice(0,1);
      masterdata = append(masterdata,data);
    }
  }
  // Clear the master sheet.
  masterSheet.clear();
  // Add the headers to the master sheet.
  var masterheadersRow = masterSheet.getRange(1, 1, 1,
    masterdata[0].length);
  masterheadersRow.setValues(headers);
  // Send the resulting array to the master sheet.
  var masterdataRange = masterSheet.getRange(2, 1, masterdata.length,
    masterdata[0].length);
  masterdataRange.setValues(masterdata);
}

/*
 * Auxiliary function to append 2D arrays.
 */
function append(a,b){
  for(var i = 0; i<b.length; i++){
    a.push(b[i]);
  }
  return a;
}

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

相关问题 通过从另一个工作表触发的脚本删除工作表中的单元格。 [谷歌工作表脚本] - Delete Cells in sheets via script that is triggered from another sheet. [google sheet script] Google表格:将文件夹范围导入母版表格 - Google Sheets: Import folder range into Master Sheet 如何在创建新工作表时自动合并 Google 表格中的单元格 - How to automatically merge cells in Google Sheets upon creation of new Sheet 如何将一张工作表的值复制到另一张工作表Google工作表脚本 - How to copy the value of one sheet to another sheet Google sheets Script 用于将多个工作表合并为一个母版的 Google App 脚本 - Google App Script to merge multiple sheets into a master 如何轻松地将大型 Google 工作表拆分为 200 行的单独工作表? - How to easily split large Google sheet into separate sheets of 200 rows? 将多个选项卡(按列,而不是逐行)合并到 Google 表格中的主表格中 - Merge multiple tabs (Column wise, not row by row) into a master sheet in google sheets 将文件夹中所有工作表的特定范围内的数据合并到主工作表 - Merge data from specific range of all sheets in a folder to a master sheet 如何合并Google表格中的行 - How to Merge rows in Google Sheets Google Sheets 使用脚本将多张工作表合并为一张工作表 - Google Sheets combine several sheets into one sheet with script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM