Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@codeas
Last active February 25, 2022 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeas/dc0c3ac492b3ab24e243cb301e82fba2 to your computer and use it in GitHub Desktop.
Save codeas/dc0c3ac492b3ab24e243cb301e82fba2 to your computer and use it in GitHub Desktop.
#GoogleSheet #GoogleSheetAPI
/*
Get filtered rows from Google Sheets
@author Ivan Kutil
Preparation: add Advanced service "Sheets" into Google Apps Script project
*/
function getFilteredRows() {
console.time("filtered-rows")
let spreadsheetId = SpreadsheetApp.getActive().getId();
let sheetName = "MySheetName"
let response = Sheets.Spreadsheets.get(spreadsheetId, {
ranges: [sheetName],
fields: "sheets",
});
let data = response.sheets[0].data[0];
let filteredRows = data.rowMetadata.reduce((agg, row, index) => {
if (!row.hiddenByFilter) {
let values = data.rowData[index].values.map( col => col.formattedValue)
agg.push(values)
}
return agg;
}, [])
console.log(filteredRows);
console.timeEnd("filtered-rows");
return filteredRows
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment