Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of last row of google spreadsheet using google app script

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.

like image 364
MOO Avatar asked Oct 19 '25 17:10

MOO


1 Answers

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
like image 148
boards188 Avatar answered Oct 22 '25 06:10

boards188



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!