是否可以通过Google应用程序脚本中的onFormSubmit调用SpreadsheetApp.getUi()? [英] Is it possible to invoke SpreadsheetApp.getUi() via onFormSubmit in google app script?
问题描述
在我的电子表格绑定脚本中,从onOpen
调用时,此代码可以正常工作.从onFormSubmit
调用时,出现以下错误:"Cannot call SpreadsheetApp.getUi() from this context."
With my spreadsheet bound script, this code works fine when invoked from onOpen
. When invoked from onFormSubmit
I get this error: "Cannot call SpreadsheetApp.getUi() from this context."
function showSidebar(issue,row) {
var html = HtmlService
.createTemplateFromFile('MySidebar');
html.issue = issue;
html.row = row;
SpreadsheetApp.getUi()
.showSidebar(html.evaluate().setTitle('Alert'));
}
推荐答案
这将无法正常工作,因为从技术上讲,电子表格不是当前实例", 用户界面".
It's not going to work because, technically, the spreadsheet isn't the "current instance" of the "user interface".
即使您的脚本已绑定到电子表格,并且getUi
可以使用其绑定到的任何文件,也可以从另一个文件中调用它.
Even though your script is bound to the spreadsheet, and getUi
works with whatever file it's bound to, it's being called from another file.
您甚至可以手动"运行该代码,通过脚本编辑器,它将添加一个自定义对话框,但是如果您从提交的表单中调用它,它将无法正常工作.
You can even run that code "manually" from the script editor, and it will add a custom dialog, but if you call it from the form being submitted, it won't work.
这篇关于是否可以通过Google应用程序脚本中的onFormSubmit调用SpreadsheetApp.getUi()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!