Appending multiple rows to Spreadsheet - Google Apps Script
I would make sure to also make a row & column variable for this snippet of code. Sometimes GAS will throw an error if you try to add the object.length directly in the getrange function. i.e.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var example = [[1,2,3],[4,5,6],[7,8,9]];
var row = example.length;
var column = example[0].length;
sheet.getRange(sheet.getLastRow()+1, 1, row, column).setValues(example);
You can use the Range.setValues() method which will set the values at once, and a script lock (or another lock, depends on your use case) to prevent other instances of the script from doing appends at the same time. You just need to get the good range (with array length) and the good position (with sheet.getLastRow() + 1 method). Here is an example:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var example = [[1,2,3],[4,5,6],[7,8,9]];
LockService.getScriptLock().waitLock(60000);
sheet
.getRange(
sheet.getLastRow() + 1,
1,
example.length,
example[0].length
)
.setValues(example);
Caveat: This does not protect against humans or other scripts.