How do I append/insert a blank/empty row in a google spreadsheet using app script?
I've tried:
var ss = SpreadsheetApp.create("test");
var sheet = ss.getActiveSheet();
sheet.appendRow(['Something']);
sheet.appendRow(['']);
sheet.appendRow(['Something Else']);
But this doesn't add a blank row. The following doesn't work either (fails with an error):
sheet.appendRow([]);
A work around is to insert a space. But then this is not a truly blank row.
sheet.appendRow([' ']);
consider:
var nextRow = sheet.getLastRow() + 1;
sheet.getRange('A' + nextRow )
.offset(0, 0, 3)
.setValues([ ['something'],
[''],
['something else'] ]);
as it sets your new values all at once
Using insertRowsAfter
(in conjunction with getMaxRows
) seemed to work for me:
var ss = SpreadsheetApp.create("test");
var sheet = ss.getActiveSheet();
sheet.appendRow(['Something']);
// Insert one empty row after the last row in the active sheet.
sheet.insertRowsAfter(sheet.getMaxRows(), 1);
sheet.appendRow(['Something Else']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With