Only get non-filtered values for Google App Script getRange using isRowHiddenByFilter or isRowHiddenByUser

别等时光非礼了梦想. 提交于 2021-01-29 13:47:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!