Google Apps Script延迟触发锁定单元格问题求助
延迟触发单元格锁定函数失效,求助传递范围参数的方法
我已编写好锁定单个单元格的代码(仅所有者可后续编辑),现在希望该锁定函数延迟10-15分钟执行,方便编辑者反悔。目前lockRow函数单独运行正常,但setUpTrigger的时间触发无法生效。
当前代码如下:
function setUpTrigger() { ScriptApp.newTrigger('lockRow') .timeBased() .after(600000) .create(); } function lockRow(e) { const sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); let protection = e.range.protect(); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); } }
我的工作是管理值班签到表,需要在有人报名班次后锁定对应单元格,这能大幅减少我的工作负担。我并非专业开发者,全靠试错走到这一步,但这个问题已经卡了我2-3周。
编辑补充:我向一位YouTube博主求助,他给出如下建议:
The 'e' value won't transfer through properly like this. You should
adjust your script so you declare and instanciate the needed values
(in this case just the range) in the setUpTrigger() function then pass
that value to the active function. So:const r = e.range; lockRow(r){ ... let protection = r.protect(); ... }
我完全不理解他的意思,恳请各位提供帮助。
内容的提问来源于stack exchange,提问作者Dislike
相关产品推荐
相关产品推荐

