'How to clear filters in Excel using xlwings?
My team are xlwings in Sypder (Python) to convert Excel tables into CSV format. When a table is filtered however, this alters the CSV output. Is there an xlwings command which can clear the filter from the active Excel sheet?
A similar command in VBA would be (from Excel 2013 VBA Clear All Filters macro):
Sub Macro1()
Cells.AutoFilter
End Sub
Solution 1:[1]
We found a way to disable filters using...
if wb.sheets[sheetname].api.AutoFilterMode == True:
wb.sheets[sheetname].api.AutoFilterMode = False
Solution 2:[2]
wb.sheets[sheetname].api.AutoFilterMode = False
Will remove the filter from the sheet, if you want to just clear the filter showing all the data without removing it you can use:
wb.sheets[sheetname].api.AutoFilter.ShowAllData()
Solution 3:[3]
This will clear the filters if any are active:
if wb.sheets[sheetname].api.AutoFilterMode:
wb.sheets[sheetname].api.AutoFilter.ShowAllData()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Finger Picking Good |
| Solution 2 | Wtower |
| Solution 3 | Mike Wochner |
