最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python clearing Excel autofilter - Stack Overflow

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论