Browse spreadsheets in the GAS and retrieve specific lines

Asked 1 years ago, Updated 1 years ago, 289 views

GAS is trying to retrieve a specific column of the spreadsheet.
A particular column is the data in the row where "num" is the maximum value in the table below.

From this table, what code should I write to get the num, user, text value of row = 4 where num is the maximum value?

I look forward to your kind cooperation.

google-apps-script

2022-12-12 14:37

1 Answers

In this case, how about the output of the built-in function as shown below?

 = SORTN (A2:C, 1, 1,)

Enter a description of the image here

Or, if you need to use Google Apps Script from the Google-apps-script tab, how about a sample script like the one below?

function sample(){
  const sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); // Enter the sheet name.
  const srcValues=sheet.getRange("A2:C" + sheet.getLastRow()) .getValues();
  constres=srcValues.sort(a,b)=>a[0]<b[0]?1:-1)[0];
  console.log(res);//<--- [4, 'C', 'Hello']
}

Both samples are sorted in descending order by column A to get the first row.

References:


2022-12-12 23:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.