Cells containing custom functions return “NaN'” when spreadsheet is not open. (Apps Script webapp accessing google spreadsheet)

前端 未结 2 1205
灰色年华
灰色年华 2020-12-18 16:00

As a high school teacher, I record all of my grading in a Google spreadsheet. I have written custom functions within that spreadsheet that are accessed in the spreadsheet. T

2条回答
  •  别那么骄傲
    2020-12-18 16:55

    With Eric's advice, I implemented the following function (which runs early on in my app):

    function refreshSheet(spreadsheet, sheet) {
      var dataArrayRange = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn());
      var dataArray = dataArrayRange.getValues(); // necessary to refresh custom functions
      var nanFound = true;
      while(nanFound) {
        for(var i = 0; i < dataArray.length; i++) {
          if(dataArray[i].indexOf('#N/A') >= 0) {
            nanFound = true;
            dataArray = dataArrayRange.getValues();
            break;
          } // end if
          else if(i == dataArray.length - 1) nanFound = false;
        } // end for
      } // end while
    }
    

    It basically keeps refreshing the sheet (using .getValues()) until all of the #N/A's disappear. It works fabulously but does add a small lag.

提交回复
热议问题