我正在使用 Google Appscript 将数据从一个工作表导入到另一个工作表。但是,当我运行代码时出现错误。
function importdata() {
var mainfile = SpreadsheetApp.getActive().getSheetByName('Data1');
var secondfile = SpreadsheetApp.openById('1232131231231abcc').getSheetByName('RAW');
var datas = secondfile.getRange('C:C').getValues();
var paste = mainfile.getRange('A:A').setValues(datas);
}
消息详情
Exception: The number of rows in the data does not match the number of rows in the range. The data has 27441 but the range has 27509. (line 6, file "Code")
最佳答案
setValues 期望您的范围与您尝试设置的数据长度具有相同的长度(必须与您的范围的尺寸相匹配)。
尝试类似的东西
var datas = mainfile.getRange('A:A').getValues()
var range = secondfile.getRange(1,1,datas.length);
range.setValues(datas);
更新:我实际上认为您的数据集中可能有“隐藏”行,这可能会导致范围与长度混淆。
关于javascript - 使用 appscript 的 SpreadsheetApp.openById 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57622062/