I'm currently automating a process using python and xlwings and need to clear any AutoFilters in a target excel worksheet. I've seen numerous samples that refer to using
if wb.sheets[sheetname].api.AutoFilterMode:
wb.sheets[sheetname].api.AutoFilter.ShowAllData()
but when I try this I get "AttributeError: Unknown property, element or command: 'AutoFilterMode'".
My test code is below and the sheet name etc is correct because other code (not shown) works fine.
import xlwings as xw
# Open the target workbook
wb = xw.Book('SOP_DL_AutofilterTest.xlsx')
ws = wb.sheets['SOP DL']
if wb.sheets['SOP DL'].api.AutoFilterMode:
wb.sheets['SOP DL'].api.AutoFilter.ShowAllData()
# Keep the window open
input("Press Enter to exit...") # This will keep the browser open until you press Enter