我正在为计划模板创建归档功能。
我通过以下代码让它工作:
// https://developers.google.com/apps-script/reference/spreadsheet/range
function copySchedule2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheets()[3];
var destination = ss.getSheets()[4];
var range = source.getRange("A1:X64");
range.copyFormatToRange(destination, 1, 26, 1, 64);
range.copyValuesToRange(destination, 1, 26, 1, 64);
}
但是,由于这是一个正在进行的存档,我正在尝试将每周的时间表添加到以前存档的底部。我尝试了这段代码:
function copySchedule() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheets()[3];
var destination = ss.getSheets()[4];
var range = source.getRange("A1:X64");
source.getRange("A:X").copyTo(destination.getRange(destination.getLastRow()+1));
}
但是我收到了一个错误:
[15-10-26 17:24:28:093 EDT] Starting execution
[15-10-26 17:24:28:099 EDT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[15-10-26 17:24:28:191 EDT] Spreadsheet.getSheets() [0.092 seconds]
[15-10-26 17:24:28:193 EDT] Spreadsheet.getSheets() [0.001 seconds]
[15-10-26 17:24:28:243 EDT] Sheet.getRange([A1:X64]) [0.049 seconds]
[15-10-26 17:24:28:302 EDT] Execution failed: Cannot convert function FindRows() { destinationRange = SpreadhseetApp.getActiveSpreadsheet().getSheets()[4].getLastRow(); return destinationRange; } 1 to (class). (line 36, file "Copy v0.5") [0.146 seconds total runtime]
我是JS的新手,所以也许有人可以指出我正确的方向。我错过了什么?
答案 0 :(得分:0)
copyTo()需要对单元格的引用才能知道它应该粘贴数据的位置。您只是给它行号,因为getLastRow()返回一个数字。
尝试附加a,1告诉它开始粘贴在A列中:
source.getRange("A:X").copyTo(destination.getRange(destination.getLastRow()+1, 1));