Reputation: 193
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.
Upvotes: 4
Views: 13230
Reputation: 104
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
Upvotes: 4