Python - How to turn-on Excel Auto Filter on cells

2020-05-03 12:09发布

I'm trying to turn-on Auto-Filter in Excel for some cells at row 5, preferably using Python Win32.

For example:

from win32com.client import Dispatch
xl = Dispatch("Excel.Application")
xl.Workbooks.Open(<file name>)
xl.ActiveWorkbook.ActiveSheet.Range('A5:D5').AutoFilter()
xl.ActiveWorkbook.Close(SaveChanges=1)
del(xl)

It still creates Auto Filter in the first row. Update: It works correctly, see comments.

I know that it is possible to set AutoFilter using ActiveSheet.Columns property, but it implies first row?

I'm using Windows XP, with Excel 2002 installed.

0条回答
登录 后发表回答