简体   繁体   English

如何使用xlwt在第一行中使用自动过滤器创建excel文件?

[英]How to create an excel file with an autofilter in the first row with xlwt?

I am using Python 2.6 + xlwt module to generate excel files. 我使用Python 2.6 + xlwt模块生成excel文件。

Is it possible to include an autofilter in the first row with xlwt or pyExcelerator or anything else besides COM? 是否可以在xlwt或pyExcelerator的第一行中包含自动过滤器或COM以外的任何其他内容?

Thanks 谢谢

AFAIK xlwt doesn't allow you to add a filter. AFAIK xlwt不允许您添加过滤器。

However you can add a filter using Mark Hammond's Python Win32 Extensions . 但是,您可以使用Mark Hammond的Python Win32 Extensions添加过滤器。 Download for 2.6 here . 在这里下载2.6。
Something like this should work (tested in Python 2.5.4): 这样的东西应该工作(在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

I found this message in a Google group. 我在Google群组中发现了此消息 It looks like it's not possible, unfortunately. 不幸的是,它似乎不可能。

I have the same issue, running a linux server. 我有同样的问题,运行Linux服务器。

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". 我将通过其他方法检查创建带有自动过滤器的ODS或XLSX文件,然后使用libreoffice命令行将它们转换为“xls”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM