Spreadsheetapp: Getrange And Setvalues
I would like to use Google SpreadsheetApp to write a 2D array into a sheet. Trying sheet.getRange(sheet.getLastRow() + 1, 1, array2d.length, array2d[0].length).setValues(array2d);
Solution 1:
When calling
sheet.getRange(sheet.getLastRow() + 1, 1, array2d.length, array2d[0].length).setValues(array2d);
You are just checking the length of the first row of your 2D-Array (using array2d[0].length
). However, different rows may have different lengths as well. You can see below a short fragment of code that reproduces your issue:
In order to continue troubleshooting your issue you may find the following hyperlinks relevant:
Solution 2:
functioninsert2DArrayIntoSheet() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
vararray=[[1,2,3],[4,5,6],[7,8,9]];
var rg=sh.getRange(1,1,array.length,array[0].length);
rg.setValues(array);
}
Post a Comment for "Spreadsheetapp: Getrange And Setvalues"