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.
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.
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. :)