【问题标题】:google script openById : You do not have permission to perform that actiongoogle script openById :您无权执行该操作
【发布时间】:2015-01-02 16:06:46
【问题描述】:

电子表格中的事件驱动脚本会打开另一个电子表格

var ss = SpreadsheetApp.openById(otherSpreadsheetId); 

查看执行记录,我收到以下错误

SpreadsheetApp.openById([0AjqSnE_p3nFqdDN0LWpFbjFqVDRwNmFGOV91QzZrZc]) [0 秒] 执行失败:您无权执行 那个动作。

当我直接在调试器中运行该函数时,我成功打开了另一个电子表格。当函数由“onEdit”事件运行时,我得到错误。

我需要启用特定的 API 吗?

【问题讨论】:

标签: google-apps-script google-sheets google-drive-api triggers


【解决方案1】:

可安装的触发器

有两种类型的 OnEdit 触发器。可安装的触发器能够“更改另一个文件”,请参阅:https://developers.google.com/apps-script/guides/triggers/installable

@kusi supplied the answer as a comment,在此处添加即可。

【讨论】:

【解决方案2】:

您可以在当前工作表中以编程方式设置可安装触发器,这样就可以调用openById

function onOpen() {
  ScriptApp.newTrigger('myOnEdit')
   .onEdit()
   .create();
}

function myOnEdit(e){
   SpreadsheetApp.openById('id_of_other_sheet');
}

【讨论】:

  • 这是直接答案(手动触发版本)。现在更容易理解该文档。大声笑。
猜你喜欢
  • 2015-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-15
  • 1970-01-01
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
相关资源
最近更新 更多