How can I get multiple filters on a single sheet?
A single filter is easy:
worksheet.auto_filter.ref = "A1:D4"
I can't figure out how to do multiple filters. I tried a few things like:
worksheet.auto_filter.ref = "A1:D4,A6:D9"
worksheet.auto_filter.ref = "A1:D4;A6:D9"
but noting works.
Thanks, Ryan
The specification says that there may be only a single auto-filter per worksheet.
As long as you're happy with working with a development version you might want to look at the 2.4 development branch which has much improved filtering and sort support. I don't use filters much myself so it could use some testing and the feedback would be very helpful.
The API has changed a bit and the best documentation is in the tests:
af = AutoFilter('A1:F1')
af.add_filter_column(5, ["0"], blank=True)
ws.auto_filter = af
Found out I can use tables to implement the sort/filter functionality. And you can have multiple tables in a single sheet. Unfortunately I can't find a way to do this in openpyxl but XlsxWriter can do this very easily.
worksheet1.add_table('A1:C4')
worksheet1.add_table('F8:H15')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With