Retrieve last line with GAS data

Asked 1 years ago, Updated 1 years ago, 68 views

I would like to use GAS to get the last row or last column with spreadsheet data.
Previously, the data up to the last line with the spreadsheet data was obtained with the following code, but the number of sheets was many, so I changed the code to the following (after the change).
Then, when I looked at varrow=sheet.getLastRow(); in the debug, the last line of data of the cell was retrieved, not the data.
I looked at the http://code-ur-life.blogspot.com/2014/03/google-apps-script-script.html site, but I don't know how to retrieve the data to the last line where the data is.

The reason I want to retrieve data is because I want to retrieve it and pass it around with forEach.

As I am a beginner, there may be some elementary questions or sentences that are strange, but if anyone understands, please let me know.
Thank you for your cooperation.

varsheet=SpreadsheetApp.getActiveSheet();
varrow=sheet.getLastRow();

Modified

var spreadsheet=SpreadsheetApp.openById (with ID);
varsheet=spreadsheet.getSheetByName('Sheet2').activate();
varrow=sheet.getLastRow();

javascript google-apps-script

2022-09-30 21:40

1 Answers

How about using getDataRange?

varsheet=SpreadsheetApp.getActiveSheet();
  range=sheet.getDataRange();
  var lastrow=range.getLastRow();


2022-09-30 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.