I want to get the last line with GAS data

Asked 1 years ago, Updated 1 years ago, 41 views

I'd 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, I found the data in the last line of the cell instead of the data.

Google Apps Script - Script to find the last row of each column in the spreadsheet

I've looked at the above sites, but I don't know how to get 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.

Enter the code here // The code that was able to retrieve the data up to the last line where the data is located
varsheet=SpreadsheetApp.getActiveSheet();
varrow=sheet.getLastRow();

javascript google-apps-script

2022-09-30 17:13

1 Answers

If you apply getValues after taking the range of data in getDataRange, you will be able to retrieve the data successfully.

getDataRange()
https://developers.google.com/apps-script/reference/spreadsheet/sheet#getDataRange()

getValues()
https://developers.google.com/apps-script/reference/spreadsheet/range#getValues()

varsheet=SpreadsheetApp.getActiveSheet();
varrows=sheet.getDataRange().getValues();
rows.forEach(function(row){
  // loop processing
});


2022-09-30 17:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.