【发布时间】:2018-04-18 21:02:12
【问题描述】:
对于我的工作,我会自动执行程序以协助我的团队成员和员工。在同事的帮助下,我们创建了一个 Google Sheets 函数,该函数可以计算所有座席的出勤点,以将它们以数组的形式显示在表单上。由于计算量大,函数往往会经常崩溃。只需将公式重新粘贴到它所在的单元格中即可解决此问题。
Google 最近发布了适用于 Google 表格的宏,我已尝试将这些宏用于此目的;然而,由于该函数位于容器绑定脚本中,因此在尝试重置工作表上的函数时,宏会产生“引用错误”。我也尝试创建一个函数来执行此操作并收到相同的结果。
我尝试使用的函数来重置工作表的单元格:
function ResetPoints(){
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getCurrentCell().setValue('').setFormulaR1C1(
'=calculateAttendancePoints(ARRAYFORMULA(Overview5.0!R11C1:R30C1))'
);
spreadsheet.getCurrentCell().offset(20, 0).activate();
spreadsheet.getCurrentCell().setValue('').setFormulaR1C1(
'=calculateAttendancePoints(ARRAYFORMULA(Overview5.0!R31C1:R50C1))'
);
spreadsheet.getCurrentCell().offset(20, 0).activate();
spreadsheet.getCurrentCell().setValue('').setFormulaR1C1(
'=calculateAttendancePoints(ARRAYFORMULA(Overview5.0!R51C1:R70C1))'
);
spreadsheet.getCurrentCell().offset(20, 0).activate();
spreadsheet.getCurrentCell().setValue('').setFormulaR1C1(
'=calculateAttendancePoints(ARRAYFORMULA(Overview5.0!R71C1:R91C1))'
);
spreadsheet.getCurrentCell().offset(21, 0).activate();
spreadsheet.getCurrentCell().setValue('').setFormulaR1C1(
'=calculateAttendancePoints(ARRAYFORMULA(Overview5.0!R92C1:R100C1))'
);
spreadsheet.getCurrentCell().offset(1, 0).activate();
}
我只用一个单元格简化了宏。公式更新为“=calculateAttendancePoints(ARRAYFORMULA(#REF!))”错误消息为“未知函数:calculateAttendancePoints
function ResetPoints() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1').activate();
spreadsheet.getCurrentCell().setValue('')
.setFormula('=calculateAttendancePoints(ARRAYFORMULA(Overview5.0!$A$11:$A$30))');
}
这是清单文件:
{
"timeZone": "America/New_York",
"dependencies": { },
"exceptionLogging": "STACKDRIVER",
"sheets": {"macros": [
{
"menuName": "calculateAttendancePoints",
"functionName": "calculateAttendancePoints"
},
{
"menuName": "ResetPoints",
"functionName": "ResetPoints",
"defaultShortcut": "Ctrl+Alt+Shift+5"
}
]}
}
有没有办法使用宏间接或通过函数重置单元格中的自定义函数?
【问题讨论】:
-
这没有意义
ARRAYFORMULA(Overview5.0!R11C1:R30C1)。另一方面,calculateAttendancePoint 可能是问题所在。这个自定义函数有什么作用? -
宏必须在容器绑定脚本中,自定义函数也是如此,所以我不确定
yet, since the function is in a container-bound script, the macro yields a "Reference error" when attempting to reset the function on the sheet.是什么意思 -
@Ruben,自定义函数在定义的范围内找到用户,计算他们所在的点,数组公式辅助显示一个范围内的数据。例如,A2:B3 john smith 2 Jack Johnson 0
-
那么,
function calculateAttendancePoints()的定义在文档的脚本文件中吗?如果不是,那么它正确地说明该功能不存在。自定义函数和宏必须在使用它们的文档中 -
calculateAttendancePoints 是宏还是自定义函数?将其添加到问题中。
标签: google-apps-script custom-function google-sheets-macros