4

How i can get the value or data from the last row of the google spreadsheet using the google app script? I was tried many times all i can do, but still cant get the data. The purpose of this to the get the last ID of the record so that I able to add another record with ID incremented.

Rubén
  • 34,714
  • 9
  • 70
  • 166
MOO
  • 183
  • 2
  • 2
  • 10

1 Answers1

4

You can use getLastRow() to get the last row that contains content, as shown here: https://developers.google.com/apps-script/reference/spreadsheet/sheet#getLastRow()

From there you should be able to get the value of your record ID. I think it would look like this, assuming your record ID's are in column 1:

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

var lastRow = sheet.getLastRow();
Logger.log(lastRow); // Row index of last row to contain data
var myIDCol = 1;
var myID = sheet.getRange(lastRow, myIDCol).getValue();
Logger.log(myID); // Should be the value of your last record ID
boards188
  • 104
  • 1
  • 8