Cannot apply AutoFilter to columns implicitly; only explicit cell ranges are accepted
Created originally on Bitbucket by kamakazikamikaze (Kent Coble)
Hi there! I think we've found a bug with filters and sorts. In release version 2.3.5, we were able to apply a filter and sort to a column (range) with the following:
ws.auto_filter.ref = 'A:B'
ws.auto_filter.add_filter_column(1, ['Inactive'])
ws.auto_filter.add_sort_condition('A')
We upgraded to 2.4.2 for good measure after hearing about the potential XXE vulnerability. Since then, we cannot apply filters to a whole column anymore (we've tested only 2.4.2 and 2.4.4). When we try to run the first or third lines from the code above, the following error is raised:
File "stalePortReport.py", line 488, in write
ws.auto_filter.ref = 'A:B'
File "/usr/local/lib/python2.7/dist-packages/openpyxl/descriptors/excel.py", line 94, in __set__
super(CellRange, self).__set__(instance, value)
File "/usr/local/lib/python2.7/dist-packages/openpyxl/descriptors/base.py", line 255, in __set__
raise ValueError('Value does not match pattern {0}'.format(self.pattern))
ValueError: Value does not match pattern ^[$]?(?P<min_col>[A-Za-z]{1,3})[$]?(?P<min_row>\d+)(:[$]?(?P<max_col>[A-Za-z]{1,3})[$]?(?P<max_row>\d+)?)?$
To get around this, we must explicitly specify the cells, such as the following:
ws.auto_filter.ref = 'A1:B145'
ws.auto_filter.add_filter_column(1, ['Inactive'])
ws.auto_filter.add_sort_condition('A2:A145')
I'm not sure if our way of using it was actually a bug and got patched or if this was accidentally removed (change to Regex pattern?). All I could find was a note in the 2.4.0-a1 release about Convert AutoFilter to Serialisable and extend support for filters
.
I've attached a workbook, should you not be able to replicate this in your own files. It's the second spreadsheet ('Building1') that we're trying to apply the filter to.
Attachments: debug.xlsx