gpt4 book ai didi

javascript - 如何以编程方式为 Google Apps 脚本中的打开事件创建触发器

转载 作者:行者123 更新时间:2023-12-02 21:28:48 27 4
gpt4 key购买 nike

我正在使用 Google Apps 脚本,并在尝试以编程方式创建触发器(未绑定(bind)到特定文件或任何内容)时遇到奇怪的错误。

我正在尝试运行特定代码 - 基本上是在 Google 文档打开时编辑文档,但我遇到了此错误:

Unexpected error while getting the method or property create on object ScriptApp.DocumentTriggerBuilder. (line 9, file "Code")DetailsDismiss

这是我正在使用的代码:

 /**
* Creates a trigger for when a spreadsheet opens.
*/
function createSpreadsheetOpenTrigger() {
var d = DocumentApp.getActiveDocument();
ScriptApp.newTrigger('myFunction')
.forDocument(d)
.onOpen()
.create();
}


function myFunction() {
// change the body or something...
}

最佳答案

如果脚本未绑定(bind)到文档,则 getActiveDocument 将不起作用。您需要 openById。

关于javascript - 如何以编程方式为 Google Apps 脚本中的打开事件创建触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60674631/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com