Writing to Excel

Robert Amesz sheershion at mailexpire.com
Thu Jun 20 11:26:07 EDT 2002


Chris wrote:

> Hi I'm using a Python cgi script to write the contents of a table
> to an Excel sheet. I retrieve all the information fine but it
> seems like Excel doesnt want to print more than one line for me.
> It prints 'headerLine' but nothing more. Why???
> 
> ... 
> headerLine = "some crap"
> 
> sys.stdout.write( Html.header( 'application/x-msexcel' ) )
> print string.strip(headerLine)
> allText = ""
> 
> ...
> # set allText = "some other crap"
> ...
> 
> print allText

My oh my, what *are* you trying to do here? Hmmm, are you trying to 
convert an ASP script by any chance? That won't work. VBS accesses 
Excel via the COM interface, and you'd need Mark Hammond's Win32all 
extension to do the same.

Not too hard, but... You'd need to have Excel installed on the web 
server, along with Python and Win32all. If that web server isn't a 
Windows machine, that's the end of the story.

But why bother with Excel at all? In most cases .CSV files will work 
equally well, and those files are a lot simpler, definitely more 
portable, and dead easy to make with Python.

Or is it that IE is set up to display Excel files directly using 
ActiveX? But what, then, would be the advantage over using HTML-tables?


Robert Amesz (slightly confused)



More information about the Python-list mailing list