Skip to main content
clarified the description
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

I guess the answer could be useful to someone that begin like me in coding...Anyway the tip here was to create a tablean array first (I named it table) instead of adding objectobjects line by line and then update the sheet in a single operation with setValues. It makes running the code way much faster !

function itemAdd(form) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = ss.getActiveSheet();      
  var nb_total = form.colis2 - form.colis1;
  var table = [];
  for (i = 0; i <= nb_total; i++) {
    if (i < form.gare){
      table.push([+form.colis1 + i, form.ddc, "A"]);
      }else{
      table.push([+form.colis1 + i, form.ddc, "B"]);
      }
    }
  feuille.getRange(feuille.getLastRow() + 1, 6, table.length, 3).setValues(table);
  }

I guess the answer could be useful to someone that begin like me in coding...Anyway the tip here was to create a table instead of adding object line by line. It makes running the code way much faster !

function itemAdd(form) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = ss.getActiveSheet();      
  var nb_total = form.colis2 - form.colis1;
  var table = [];
  for (i = 0; i <= nb_total; i++) {
    if (i < form.gare){
      table.push([+form.colis1 + i, form.ddc, "A"]);
      }else{
      table.push([+form.colis1 + i, form.ddc, "B"]);
      }
    }
  feuille.getRange(feuille.getLastRow() + 1, 6, table.length, 3).setValues(table);
  }

I guess the answer could be useful to someone that begin like me in coding...Anyway the tip here was to create an array first (I named it table) instead of adding objects line by line and then update the sheet in a single operation with setValues. It makes running the code way much faster !

function itemAdd(form) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = ss.getActiveSheet();      
  var nb_total = form.colis2 - form.colis1;
  var table = [];
  for (i = 0; i <= nb_total; i++) {
    if (i < form.gare){
      table.push([+form.colis1 + i, form.ddc, "A"]);
      }else{
      table.push([+form.colis1 + i, form.ddc, "B"]);
      }
    }
  feuille.getRange(feuille.getLastRow() + 1, 6, table.length, 3).setValues(table);
  }
Source Link

I guess the answer could be useful to someone that begin like me in coding...Anyway the tip here was to create a table instead of adding object line by line. It makes running the code way much faster !

function itemAdd(form) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var feuille = ss.getActiveSheet();      
  var nb_total = form.colis2 - form.colis1;
  var table = [];
  for (i = 0; i <= nb_total; i++) {
    if (i < form.gare){
      table.push([+form.colis1 + i, form.ddc, "A"]);
      }else{
      table.push([+form.colis1 + i, form.ddc, "B"]);
      }
    }
  feuille.getRange(feuille.getLastRow() + 1, 6, table.length, 3).setValues(table);
  }