Link Google 个要列出 Google 个表格的列表

Link list of Google Forms to list Google Sheets

我有一个模板 google 表单,我需要为其创建副本并 link 到特定 sheet。我需要重复此过程 200 多次,因为我们有 200 个特定 sheet.

如果我制作表格的副本,并使用 200 个表格的列(A 列),然后在另一列(B 列)上使用 200 个特定的 sheets 有没有办法制作link 将 Col A 中的表单转换为 Col B 中相应的 sheet 的脚本。

您可以试试这个示例 Google 电子表格 bound script below, which is based from a sample at FormApp DestinationType 文章:

The script below creates copies of the Google Form template file (they'll be saved to your Google Drive via a Folder named "FormTemplateCopies") and each copies will be linked to the Spreadsheet files added on your sheet (the spreadsheet URLs on Column B).

示例脚本

function linkToForms() {
  var ss = SpreadsheetApp.getActive().getActiveSheet();
  //URLs of the sheet files are in Column B
  var urls = ss.getRange("B2:B"+ss.getDataRange().getLastRow()).getValues(); 
  //File ID of the Form template file is on A2
  var templateFileID = ss.getRange("A2").getValue(); 

  urls.forEach(url => {
      var form = FormApp.openById(formCopyID(templateFileID));
      var ss = SpreadsheetApp.openByUrl(url);
      // Update the form's response destination.
      form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
      Logger.log("Done linking a copy of Form template file to sheet file \""+ss.getName()+"\"");
  });
}

function formCopyID(templateFileID) {
  var destFolder = DriveApp.getFoldersByName("FormTemplateCopies");
  if(destFolder.hasNext() == false){
    //Create a folder to contain the copies of the Form template file
    DriveApp.createFolder("FormTemplateCopies"); 
    linkToForms();
  }else{
    var dstFolderId = destFolder.next().getId();
    //Put the file ID of the original Form template file
    var fileToCopy = DriveApp.getFileById(templateFileID);
    //Creates a copy of the Form template file and place it into the FormTemplateCopies folder in your Google Drive
    var newCopyfile = fileToCopy.makeCopy(DriveApp.getFolderById(dstFolderId));
    //Gets the file ID of the new copy of the Form template file
    return newCopyfile.getId();
  }
}

示例结果:

Sample sheet file with data (Form template file ID was added on cell A2 & 2 sample Spreadsheet file URLs were added on cell B2 and below)

After running the function linkToForms() on the Apps Script editor, here's the result

表单模板的副本现在链接到 Sheet 1:

表单模板的另一个副本现在链接到 Sheet 2: