根据Google表格基础表中的范围从模板表创建新表

时间:2019-02-22 19:44:47

标签: google-apps-script google-sheets

不确定为什么不根据范围(J1:J5)制作新图纸吗?它只是复制“模板”。

function makeCopies() {
  //getting active spreadsheet
  var activeSreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  //getting basic sheet
  var basicSheet = activeSreadsheet.getSheetByName("base");
  //getting active spreadsheet
  var activeSreadsheet2 = SpreadsheetApp.getActiveSpreadsheet();
  //getting template sheet
  var templateSheet = activeSreadsheet2.getSheetByName("template");  
  //setting template sheet as active
  activeSreadsheet2.setActiveSheet(templateSheet);
  //getting values from selected range
  var rangeArr = basicSheet.getRange("J1:J5").getValues();
  //going through range values
  for (i = 0; i < rangeArr.length; i++) {
    //preparing name for new sheet
    var name = (i + 2) + '. ' + rangeArr[i][0];
    //making duplicate of base sheet
    var newSheet = SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
    //setting new name for duplicated sheet
    if (name) {
      Logger.log("name" + rangeArr[i] + "already exists");
    } else {
      template.copyTo(ss).setName(rangeArr);
    }
  }
  return;
}

0 个答案:

没有答案