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);
}