Google script - Exceeded maximum execution time , help optimize

后端 未结 2 876
梦毁少年i
梦毁少年i 2021-01-25 10:42

google script spreadsheet Novice

I try to create a matrix , if the array is a small database everything works fine, of course if it exceeds 800 lines and more rests on t

2条回答
  •  孤街浪徒
    2021-01-25 11:02

    this code:

    var Valus = numbr.getValues().toString();
    

    slows you down because you read data from the sheet in a loop.

    Try reading data once into array and then work with it:

    var data = s.getDataRange().getValues();
    

    And then work with data, in a loop. This sample code log each cell in active sheet:

    function logEachCell() {
      var s = SpreadsheetApp.getActiveSheet();
      var data = s.getDataRange().getValues();
    
      // loop each cell
      var row = [];
      for (var i = 0; i < data.length; i++) {
        row = data[i];
        for (var j = 0; j < row.length; j++) {
          Logger.log(row[j])      
        } 
      }
    }
    

提交回复
热议问题