我正在尝试创建一个脚本,该脚本允许用户将突出显示的单元格区域复制到另一个未打开的Google表格文档中。如果要将数据复制到的工作表在当前文档中,则可以使它工作,但是我无法弄清楚如何将数据复制到其他电子表格中。我已经尝试过openById或openbyUrl,但是我一直收到以下错误:“目标范围和源范围必须在同一电子表格上。”function copyToDifferentDocument() { var ss = SpreadsheetApp.getActiveSpreadsheet();// *** Have to figure out how to make the target a different document!!!! *** var target = SpreadsheetApp.openById("targetsheetIDgoeshere"); /* Next we need to pick the particular sheets within those spreadsheets. Let's say your row is on the sheet named "New Stuff", and you have a sheet in the target spreadsheet named "Archive". */ var source_sheet = ss.getSheetByName("New Stuff"); var target_sheet = target.getSheetByName("Archive"); // The below makes the highlighted cells the range that will be copied. var source_range = source_sheet.getActiveRange(); var last_row = target_sheet.getLastRow(); target_sheet.insertRowAfter(last_row); var target_range = target_sheet.getRange("A"+(last_row+1)+":G"+(last_row+1)); // Take the highlighted rant and put it on the last row of the target sheet. source_range.copyTo(target_range);}我正在尝试突出显示范围以复制到其他Google工作表文档中的工作表。
添加回答
举报
0/150
提交
取消