如何在我的脚本运行时在 Google 表格中添加“正在加载..”消息,以便用户知道脚本仍在运行?

问题描述 投票:0回答:1

因此,当用户单击工作表中的按钮时,我会运行一个脚本。该按钮链接到脚本。我希望弹出加载消息,以便他们知道脚本仍在运行并且不会编辑选项卡中的任何内容。

我尝试了几个可以在网上找到的脚本,但它没有按预期工作。

这是我尝试过的,但它没有做任何事情。

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');

}

所以基本上我想要的是

  1. 单击按钮,脚本运行
  2. 当脚本运行时,加载消息将出现在工作表中的某处
  3. 脚本完成,加载消息消失。没有弹出任何其他消息。
google-sheets google-apps-script
1个回答
0
投票

您遗漏了 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');

}
© www.soinside.com 2019 - 2024. All rights reserved.