views:

301

answers:

2

Hi, 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

A: 

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

jbochi
A: 

AFAIK xlwt doesn't allow you to add an "autofilter".

But you can add an "autofilter" 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 Dispatch
>>> xl = Dispatch("Excel.Application")
>>> xl.Workbooks.Open("c:/full/path/to/your/excel_file.xls")
>>> xl.ActiveWorkbook.ActiveSheet.Columns(1).AutoFilter(1)
>>> xl.ActiveWorkbook.Close(SaveChanges=1) # 1 is True, 0 is False
>>> xl.Quit()
Adam Bernier
Hi, thanks for your answer, but my server is running on Linux so I am unable to use the COM. :-(
jbochi
@jbochi: No problem. You may want to update the question with this additional piece of information.
Adam Bernier