Home > Software design >  Returning the appended row number after sheet.appendRow
Returning the appended row number after sheet.appendRow

Time:09-26

Is there a way of returning the newly appended row number into a google sheet with the following code appendRow code? I can guarantee that the sheet will not be sorted but I cannot guarantee that the sheet will not have another row append before I call the number of rows of data in the sheet.

var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0];

// Appends a new row with 3 columns to the bottom of the // spreadsheet containing the values in the array sheet.appendRow(["a man", "a plan", "panama"]);

Thanks Dave

CodePudding user response:

appendRow() returns the Sheet object for chaining. If you want the row number, you need to call getLastRow() (see docs) immediately after appending. If you have concurrent appends, you can use the Lock Service to make sure to avoid conflicts.

  • Related