Google script - Exceeded maximum execution time , help optimize

后端 未结 2 877
梦毁少年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 10:53

    You're doing a call to getValues every row, that eats a lot of performance.
    It is better to do one big call to have all the data and then go through it sequentially.

    var s = SpreadsheetApp.getActiveSheet();
    var data = s.getRange(1,4, s.getLastRow()).getValues();
    
    var toAddArray = data.map(function(row, i) {
      var Valus = row[0].toString();
      var newznach = Valus.
        replace(/\-/g, "").
        replace(/[0-9][0-9][0-9][0-9][0-9][a-zA-Zа-яА-Я][a-zA-Zа-яА-Я]/g, "").
        replace(/[a-zA-Zа-яА-Я][a-zA-Zа-яА-Я]/g, "");
    
      return [i.toFixed(0), Valus, newznach];
    });
    

提交回复
热议问题