Last active
February 25, 2022 16:51
-
-
Save codeas/dc0c3ac492b3ab24e243cb301e82fba2 to your computer and use it in GitHub Desktop.
#GoogleSheet #GoogleSheetAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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