Google脚本文档openbyid权限错误 [英] Google Script document openbyid permission error
问题描述
如果我在Google文档的onOpen函数中通过按ID打开电子表格来创建电子表格对象,那么如果我使用菜单系统,该如何将该对象传递给其他功能? (下面将进行详细说明)
If in the onOpen function of a Google Doc I create a spreadsheet object by opening a spreadsheet by id, how can I pass that object to other functions if I'm using the menu system? (longer explanation below)
我有一个google doc脚本,它将在特定时间拍摄文档快照,然后将其导出到.docx并使用快照的URL更新电子表格.这是通过像这样的菜单选项启动的:
I have a google doc script that will take a snapshot of a document at a particular time and then export that to .docx and update a spreadsheet with the url of the snapshot. This is initiated by a menu option like so:
function onOpen(e) {
DocumentApp.getUi().createMenu('Senate Secretary Menu')
.addItem('Snapshot', 'snapshot')
.addToUi();
}
哪个调用函数snapshot()
Which calls the function snapshot()
function snapshot() {
//open the spreadsheet using id
var ss=SpreadsheetApp.openById('spreadsheet_id');
这会产生you do not have permission to call openbyid()
错误
我知道google脚本禁止在自定义函数中调用openbyid()(我将其解释为电子表格中的函数,但是whatevs). 如果我将onOpen函数更改为包括OpenById()调用,它将起作用.
I understand that google script prohibits openbyid() from being called in custom functions (which I interpreted as functions in spreadsheet, but whatevs). if I change the onOpen function to include the OpenById() call it will work.
function onOpen(e) {
DocumentApp.getUi().createMenu('Senate Secretary Menu')
.addItem('Snapshot', 'snapshot')
.addToUi();
var ss=SpreadsheetApp.openById('spreadsheet_id');
}
我的问题是如何将文件对象从onOpen函数传递给快照函数?
My question is how can I pass the file object from the onOpen function to the snapshot function?
推荐答案
对于可能也有此问题的任何人.我从Google快速入门中获取了菜单模板,但在我错过的标题注释栏中有@OnlyCurrentDoc
标志.拿出来解决了我的问题.
For anyone who might also have this problem. I took the menu template from the Google Quickstart, but it has @OnlyCurrentDoc
flag in the header comment block that I missed. Took that out and my problem was solved.
这篇关于Google脚本文档openbyid权限错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!