2

I'm using

  sheet.getDataRange() 

to get all cells. It fetch all rows even hidden (that was filtered).

How can I get only not hidden rows (the rows that user see when he/she opens a spreadsheet)?

Thank you.

Auguste
  • 2,007
  • 2
  • 17
  • 25
Anton
  • 442
  • 4
  • 19

1 Answers1

0

Actually, there is already an existing issue on Integration of Tools/Filter with google apps script and, based on that issues tracker, this feature hasn't been added yet.

You may, however, try alternative solutions given in this SO post - Google Script Filter Or Hide Row. One of the solutions given is by reducing a set of data with the use of an array and a hide method as shown below.

function MasterFilter() {
  var headers = 4; // # rows to skip
  var sheet = SpreadsheetApp.getActiveSheet();
  var maxRows = sheet.getMaxRows();

  //show all the rows
  sheet.showRows(1, maxRows);

  //get data from column B
  var data = sheet.getRange('B:B').getValues();

  //iterate over all rows
  for(var i=headers; i< data.length; i++){
    if(data[i][0] == false){
      sheet.hideRow(sheet.getRange(i+1,1));
    }
  }
}

I hope one of the solutions given works for you. :)

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22
  • 1
    Thanks for answer. I need something like `row.isHidden()`. But it is not implemented too. I've found similar [post on SO](http://stackoverflow.com/questions/6793805/how-to-skip-hidden-rows-while-iterating-through-google-spreadsheet-w-google-app) – Anton May 25 '16 at 08:47