Writing to ms excel

Leonhard Vogt leonhard.vogt at gmx.ch
Sat Aug 30 21:56:00 CEST 2008

Marin Brkic schrieb:
> I'm trying to find a way to write data to excel cells (or to be more
> specific to an .xls file), let's say for the sake of argument, data
> readen from a file (although it will be calculated in the process).
> I've been searching, but couldn't find any examples which allows that.

If you have Excel installed you can use COM to access Excel and to
"remote-control" it in order to save a .xls file.

I have no Windows nor Excel at the moment, so I can only write something
approximative. Searching for win32com will help.

excel = win32com.client.Dispatch("Excel.Application")
wbook = excel.NewDocument()
sheet = wbook.Worksheets("Sheet1")
sheet.Cells(1,1) = "Abc"
excel.close() or destroy()

The objects available are very similar to the VBA objects, so recording
a macro and translating its VBA source to python should not be hard.


More information about the Python-list mailing list