【发布时间】:2020-12-15 17:13:13
【问题描述】:
我有一个电子表格,其中包含一些我想在其他电子表格脚本中使用的数据表。如何通过 ID 调用此电子表格并访问数据?\
从documentation,我知道自定义函数不允许访问其他电子表格,解决方案是将此函数放在菜单中并运行它,因为它会要求用户授权。但这不是一个选项,因为我使用的是内置方法 onEdit() 的数据。\
另外,我尝试通过onOpen() 访问电子表格,因为它不是自定义函数,但仍然没有成功。还有其他解决方案吗?
我的代码:
function onOpen(){
ss = SpreadsheetApp.getActiveSpreadsheet();
src = SpreadsheetApp.openById("spreadsheetID");
错误信息:
Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets
还有appscript.json
{
"timeZone": "Europe/Paris",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets"
]
}
最后,我还尝试使用以下代码创建installable trigger:
function createSpreadsheetOpenTrigger() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ScriptApp.newTrigger('myFunction')
.forSpreadsheet(ss)
.onOpen()
.create();
}
但是在打开工作表时似乎没有调用触发器。
【问题讨论】:
-
您能否将您的问题限制为 1 个问题:最好只有从“最后,我也尝试过 cr...”开始的最后一部分。是什么让您认为触发器不起作用?
-
@TheMaster 毕竟这是一个问题。我只是提出了我的尝试。而且我不知道为什么它不起作用。我尝试使用
myFunction从仪表板中的触发器页面手动创建触发器,它似乎工作 -
那么问题解决了吗?
标签: javascript google-apps-script google-apps