How to create an excel file with an autofilter in

2019-04-28 20:50发布

I am using Python 2.6 + xlwt module to generate excel files.

Is it possible to include an autofilter in the first row with xlwt or pyExcelerator or anything else besides COM?

Thanks

3条回答
等我变得足够好
2楼-- · 2019-04-28 21:25

I have the same issue, running a linux server.

i'm going to check creating an ODS or XLSX file with auto-filter by other means, and then convert them with a libreoffice command line to "xls".

查看更多
贪生不怕死
3楼-- · 2019-04-28 21:33

AFAIK xlwt doesn't allow you to add a filter.

However you can add a filter using Mark Hammond's Python Win32 Extensions. Download for 2.6 here.
Something like this should work (tested in Python 2.5.4):

from win32com.client import DispatchEx
xl = DispatchEx("Excel.Application")
xl.Workbooks.Open("c:/excel_file.xls")
xl.ActiveWorkbook.ActiveSheet.Columns(1).AutoFilter(1)
xl.ActiveWorkbook.Close(SaveChanges=1)
xl.Quit()
del xl # ensure excel.exe process ends
查看更多
劳资没心,怎么记你
4楼-- · 2019-04-28 21:36

I found this message in a Google group. It looks like it's not possible, unfortunately.

查看更多
登录 后发表回答