Google Apps Script中copyTo方法参数不匹配执行错误求助
谷歌表格脚本执行错误问题
错误详情
执行脚本时抛出以下错误:
Exception: The parameters (SpreadsheetApp.Range,number,(class)) don't match the method signature for SpreadsheetApp.Range.copyTo.
错误指向代码行:
validationSource.copyTo(validationDestination, SpreadsheetApp.CopyPasteType.PASTE_DATA_VALIDATION, false);
已确认validationSource和validationDestination均为通过.getRange()获取的Range类型对象。
疑问点
- 未对代码做任何修改,此前运行正常,现在突然报错?
- 错误提示中参数类型显示为
(SpreadsheetApp.Range,number,(class)),但传入的第三个参数是布尔值false,为何会显示为(class)?尝试用1==0强制生成布尔值传入,仍出现相同错误,怀疑是Google Apps Script的bug。
示例代码
function onEdit(e) { for (let c=1; c <= e.range.getNumColumns(); c++) { for (let r=1; r <= e.range.getNumRows(); r++) { let cell = e.range.getCell(r, c); let validationSource = e.source.getSheetByName("Lists").getRange("A1"); let validationDestination = e.source.getSheetByName("Ratings").getRange(cell.getRow(), cell.getColumn()+3); if ( cell.getValue() ) { validationSource.copyTo(validationDestination, SpreadsheetApp.CopyPasteType.PASTE_DATA_VALIDATION, false); } else { validationDestination.setDataValidation(null).clearContent(); } } } };
内容的提问来源于stack exchange,提问作者Majal
相关产品推荐
相关产品推荐

