Saturday, September 30, 2023

simple efficient code to push multiple rows of data into a google sheet

As mentioned in
https://spreadsheet.dev/write-multiple-rows-to-google-sheets-using-apps-script
it is much more efficient to use Google Apps Script Spreadsheetapp function
Range -> setValues()
rather than
Sheet -> appendRow()

Concise code snippet, similar to what is used in a function in one of my private repos "Search results to sheet":

var data = [];
// add as many times as needed in a loop
data.push([value1, "value2", value3]);
//
var lastRow = SpreadsheetApp.getActiveSheet().getLastRow();
SpreadsheetApp.getActiveSheet().getRange(lastRow + 1,1,data.length, 
data[0].length).setValues(data); 

No comments:

Post a Comment