Dialog

Opening Dialog Box during Calculation and Retrieving Calculated Result using Google Apps Script

Gists

  1. When it starts a calculation, open a dialog box.
  2. When the calculation is finished, close the dialog and retrieve the calculated result.

This is a sample script for achieving above flow. This sample script supposes to use the container-bound script of Spreadsheet. When you use this, please run the function of run().

Sample script:

function doSomething(e) {

  // Scripts for calculating.

  Utilities.sleep(3000); // This is a sample wait time.
  var data = "data";
  main({result: data});
}

function openDialogue() {
  var html = "<script>google.script.run.withSuccessHandler(function() {google.script.host.close()}).doSomething();</script>";
  var h = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(h, "Sample");
}

function main(e) {
  if ("result" in e) return e.result;
  openDialogue(e);
}

// Please run this function.
function run() {
  var res = main({});
    Logger.log(res);
}

Note:

  • This can be also used for the sidebar and other Google Docs.

Closing Existing Sidebar using Google Apps Script

Gists

This is a sample script for closing the existing sidebar using Google Apps Script. When the sidebar is opened, in order to close the sidebar, the sidebar can be closed by running google.script.host.close() with the script of sidebar. This is the general case.

If you want to close the opened sidebar, such functions are not prepared. So I thought this workaround. The flow of this workaround is as follows.

Open Site with New Window using Google Apps Script

Gists

This is a sample script for opening a site with new window using Google Apps Script. It is possible to open the site inside the opened dialog box using iframe. But in my situation, I had to open the site as new window. So I created this. As a sample application, it can think of like this. When the special keyword was inputted, open sites and files in Google Drive as a help window. In this case, the trigger installed onEdit() is required to be used. I think that there are some other applications.