因此,当用户单击工作表中的按钮时,我会运行一个脚本。该按钮链接到脚本。我希望弹出加载消息,以便他们知道脚本仍在运行并且不会编辑选项卡中的任何内容。
我尝试了几个可以在网上找到的脚本,但它没有按预期工作。
这是我尝试过的,但它没有做任何事情。
function showDialog() {
var ui = SpreadsheetApp.getUi();
// Display a modal dialog box with custom HtmlService content.
var htmlOutput = HtmlService
.setWidth(250)
.setHeight(300);
ui.showModalDialog(htmlOutput, 'Script Running');
}
所以基本上我想要的是
您遗漏了 HTML 服务生成 HTML 输出的方法。
您可以尝试以下方法。
function showDialog() {
var ui = SpreadsheetApp.getUi();
// Display a modal dialog box with custom HtmlService content.
var htmlOutput = HtmlService.createHtmlOutput('Loading...')
.setWidth(250)
.setHeight(300);
ui.showModalDialog(htmlOutput, 'Script Running');
// Added a sleep so you can see the transition
Utilities.sleep(3000);
// This output will close the modal
var closeModal = HtmlService.createHtmlOutput('<script>google.script.host.close();</script>')
.setWidth(250)
.setHeight(300);
ui.showModalDialog(closeModal,'Script Running');
}