函数运行时的Google Apps脚本刷新表

Gh*_*KU 1 google-sheets google-apps-script

我的Google表格中有一些脚本/完成所有这些脚本可能要花很多时间(我认为最多需要5分钟)。我想显示一些消息,用户应该稍等一下。所以我有一些类似的代码:

function test(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var cell = sheet.getRange("A1");
  sheet.clear();
  cell.setValue('WAIT!!!!');
  DATA = UrlFetchApp.fetch(url);
  // And some action that takes a lot of time ....
  cell.setValue('DONE!!!!');
Run Code Online (Sandbox Code Playgroud)

但是它不会显示“ WAIT”,而在一切正常的情况下只会显示“ DONE”。如果出现任何错误并且功能崩溃,它只能显示“ WAIT”。看来我需要以某种方式刷新它。

小智 5

将单元格值设置为等待后,调用flush()方法。

SpreadsheetApp.flush(); //Applies all pending Spreadsheet changes.
Run Code Online (Sandbox Code Playgroud)