使用脚本编辑器功能mergesheets(){

时间:2019-05-02 15:03:41

标签: google-sheets merge spreadsheet google-sheets-api

我正在尝试将多个电子表格中的数据收集到一个电子表格中。使用此代码在哪里可以纠正错误?

function mergeSheets() {

  /* Retrieve the desired folder */
  var myFolder = DriveApp.getFoldersByName(SOURCE).next();

  /* Get all spreadsheets that resided on that folder */
  var spreadSheets = myFolder.getFilesByType("application/vnd.google-apps.spreadsheet");

  /* Create the new spreadsheet that you store other sheets */  
  var newSpreadSheet = SpreadsheetApp.create("Merged Sheets");

  /* Iterate over the spreadsheets over the folder */
  while(spreadSheets.hasNext()) {

    var sheet = spreadSheets.next();

    /* Open the spreadsheet */
    var spreadSheet = SpreadsheetApp.openById(sheet.getId());

    /* Get all its sheets */
    for(var y in spreadSheet.getSheets()) {

      /* Copy the sheet to the new merged Spread Sheet */
      spreadSheet.getSheets()[y].copyTo(newSpreadSheet); 
    }
  }      
}

0 个答案:

没有答案