问题
I'm fairly new, trying to do the same thing as Only get non-filtered values for Google App Script getRange - get all rows that aren't hidden without using an added column. Make it generic so that regardless of what fields were used to hide rows, I'll only be acting on the non-hidden. I've been playing with isRowHiddenByFilter() and isRowHiddenByUser() but not getting it. To get all unfiltered rows, would I need to check that isRowHiddenByFilter() and isRowHiddenByUser() are both false?
It seems like the above should work with something like (not sure how the NOT is specified):
for(var i=0;i<range.length;i++){
if (NOT range.isRowHiddenByFilter){
filter.push(range[i][0])
}}
回答1:
Flow:
- Get All values and use Array.filter to filter out hidden rows
Sample script:
const getVisibleValues_ = (shtName, rngString, sheet, range) => {
sheet = sheet || SpreadsheetApp.getActive().getSheetByName(shtName);
return (range || sheet
.getRange(rngString))
.getValues()
.filter(
(_, rowIdx) =>
!sheet.isRowHiddenByFilter(rowIdx + 1) &&
!sheet.isRowHiddenByUser(rowIdx + 1)
);
};
const test1 = () => console.info(getVisibleValues_('Sheet1', 'B1:B70'));
来源:https://stackoverflow.com/questions/61306254/only-get-non-filtered-values-for-google-app-script-getrange-using-isrowhiddenbyf