Recently, I've discovered XlsxWriter for Python (and I do enjoy it!) and I started working on some spreadsheet. I need to programmatically create a spreadsheet identical to one created manually by some other person. I managed to create everything I needed except for sorting table in autofilter. Basically, I would like to create something like this: and I couldn't figure out how. I checked with the documentation (1, 2) and didn't find any information about sorting. What I do now is:
worksheet.autofilter(1, 0, known_lenght, known_width)
which results in autofilter arrow appearing in lower right corner of header cells but worksheet.autofilter()
seems to lack sorting capability. Am I missing something or is there no option to create autofilter and set sorting in it in XlsxWriter? Thanks!
Am I missing something or is there no option to create autofilter and set sorting in it in XlsxWriter?
Sorting of data in Excel is done at runtime and isn't a function of the file format. As such it isn't supported by XlsxWriter.
Instead you should sort the data in Python and then write it to the autofilter region.
However, that won't set the autofilter arrow to "sorted". That isn't currently supported in XlsxWriter.
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