Hi!
I’ve added a macro to reset filter on a sheet to my existing calc document, but found it works strange. On some sheets it works properly, on other not: when run, all rows became visible, but filter is not reset.
I’m using 32-bit version 6.0.7.3 mostly (due to old laptop), but I have tested it with 7.3.7.2 64-bit, but with the same behavior.
Here is the macros (first row is specified because some sheets contain filter in the first row, some in second, but both work proper and improper for different sheets)
function getUsedArea(sheet,optional startRow) ' macro to get range of data
cur = sheet.createCursor()
cur.gotoStartOfUsedArea(False)
cur.gotoEndOfUsedArea(True)
adr = cur.getRangeAddress()
if isMissing(startRow) then startRow = adr.StartRow
getUsedArea = sheet.getCellRangeByPosition(adr.StartColumn,startRow,adr.EndColumn,adr.EndRow)
end function
sub clear_filter(sheet,startRow) ' macro to clear filter
rng = getUsedArea(sheet,startRow)
fd = rng.createFilterDescriptor(True)
fd.ContainsHeader = True
rng.filter(fd)
end sub
sub clear_filter_0 ' macro to clear filter if headers are in the 1st row
clear_filter(ThisComponent.CurrentController.getActiveSheet,0)
end sub
sub clear_filter_1 ' macro to clear filter if headers are in the 2nd row
clear_filter(ThisComponent.CurrentController.getActiveSheet,1)
end sub
I’ve cleared data and extra stuff from my document to make the example. How to reproduce: set filter on any sheet and press button “all” - see the result.
I would be thankful if somebody can explain why it works in this way and how it should be done properly.
filter_test.ods (34.5 KB)