How to skip hidden rows while iterating through Google Spreadsheet w/ Google Apps Script

前端 未结 5 1040
再見小時候
再見小時候 2020-12-17 18:40

I have a Google Spreadsheet with many hidden rows in it, and I want to skip them when iterating through a list of rows in the spreadsheet.

It\'s mainly an efficienc

5条回答
  •  再見小時候
    2020-12-17 19:39

    A workaround using SUBTOTAL. Create 2 columns A and B. A must always have a value and B has a set of formulas. These 2 columns look like this:

    A |           B
    ---------------------------
    1 | =NOT(SUBTOTAL(103, A1))
    1 | =NOT(SUBTOTAL(103, A2))
    1 | =NOT(SUBTOTAL(103, A3))
    

    SUBTOTAL returns a subtotal using a specified aggregation function. The first argument 103 defines the type of function used for aggregation. The second argument is the range to apply the function to.

    • 3 means COUNTA and counts the number of values in the range
    • +100 means ignore hidden cells in the range.

    The result of SUBTOTAL with a range of 1 cell will be 0 when the cell is hidden and 1 when the cell is shown. NOT inverts it.

    Now you can read the column B with your script to know if a row is hidden.

    Here's the transposed question and answer: https://stackoverflow.com/a/27846180/1385429

提交回复
热议问题