【问题标题】:Google Apps Script Close()Google Apps 脚本关闭()
【发布时间】:2013-08-20 22:13:48
【问题描述】:

是否可以关闭在 Apps 脚本中打开的 UI 窗口?

我认为答案是否定的:http://code.google.com/p/google-apps-script-issues/issues/detail?id=474&can=1&q=.close%28%29&colspec=Stars%20Opened%20ID%20Type%20Status%20Summary%20Component%20Owner

但我想看看有没有其他意见。

我有一个弹出的“等待窗口”,我想在活动完成后关闭它。


var app = UiApp.getActiveApplication();

var ss = SpreadsheetApp.getActiveSpreadsheet();

var sheet = getSheetWithSubmissions(ss);

// create UI app, this works fine

app = createWaitPleaseUI(sheet);

ss.show(app);

//simulated activity

Utilities.sleep(5000);

//this doesn't work despite being in the documentation

app.close();

认为这是不可能的,但如果无法做到,希望 Google 将其从他们的文档中删除。

作为一种解决方法,我可以调出第二个 GUI,说“工作完成,单击确定”,然后它就可以正常工作了。

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    您必须返回 app 对象才能对其进行更新,甚至关闭。

    将最后一行改为return app.close()

    【讨论】:

      【解决方案2】:

      您应该更彻底地阅读文档,其中清楚地解释了电子表格中的 UI 需要通过返回实际关闭来结束。另外我建议你可以相信来自顶级贡献者的答案,而不是相信你总是对文档和其他人是正确的......没有冒犯,但总是欢迎一点谦逊:-)

      这里是从documentation中提取的一段代码来证实:

      // Close everything return when the close button is clicked
      function close() {
        var app = UiApp.getActiveApplication();
        app.close();
        // The following line is REQUIRED for the widget to actually close.
        return app;
      }
      

      【讨论】:

      • 请注意,您所指的问题不适用于您的示例:它是关于独立 UI,而不是电子表格中的 UI。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      相关资源
      最近更新 更多