无法插入表格

时间:2012-12-03 05:35:18

标签: google-apps-script google-sheets google-docs google-spreadsheet-api

我收到错误消息:“指定的工作表必须是电子表格的一部分”。我假设“指定的工作表”是sourceSheet ...但谁知道。这是什么试图告诉我的?更好的是,我该如何解决?我想将电子表格“File1”中的工作表插入电子表格“File2”。

谢谢

function copyTemplate() {

  var targetID="0Atn-Fxxxxt5YdF9VVxxxxxxxlZlVmeXoxxxzJuQ3c";

  // The code below will duplicate the sheet named "CellData" and insert it after 
  // the 1st sheet and call it "CellData"

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sourceSheet = ss.getSheetByName("CellData");

  var targetFile=SpreadsheetApp.openById(targetID);  

  targetFile.insertSheet("CellData", 1, {template:sourceSheet});   

}

1 个答案:

答案 0 :(得分:1)

function copyTemplate() {
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName('CellData')
  .copyTo(SpreadsheetApp.openById('0Atn-Fxxxxt5YdF9VVxxxxxxxlZlVmeXoxxxzJuQ3c'));
}