Excel file interface for Python 2.3?

kyosohma at gmail.com kyosohma at gmail.com
Tue Jun 12 09:39:31 EDT 2007


On Jun 12, 8:38 am, kyoso... at gmail.com wrote:
> On Jun 12, 8:01 am, "Hamilton, William " <wham... at entergy.com> wrote:
>
> > I'm in need of a module that will let me create Excel workbooks from within
> > Python.  Something like PyExcelerator, but it needs to work with Python 2.3.
> > (A third-party limitation that I have no control over.)  Can anyone point me
> > to what I need?  All my searches keep leading back to PyExcelerator.
>
> > --
> > -Bill Hamilton
>
> You can also use COM if you're on Windows, via PyWin32. Hammond's book
> talks about it a little here:http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html
>
> I also saw some information about this in Core Python Programming by
> Chun.
>
> Example code follows:
>
> <code>
>
> import win32com.client as win32
> def excel():
>     app = 'Excel'
>     xl = win32.gencache.EnsureDispatch('%s.Application' % app)
>     ss = xl.Workbooks.Add()
>     sh = ss.ActiveSheet
>     xl.Visible = True
>     sleep(1)
>
>     sh.Cells(1,1).Value = 'Python-to-%s Demo' % app
>     sleep(1)
>     for i in RANGE:
>         sh.Cells(i,1).Value = 'Line %d' % i
>         sleep(1)
>     sh.Cells(i+2,1).Value = "Th-th-th-that's all folks!"
>
>     ss.Close(False)
>     xl.Application.Quit()
>
> </code>
>
> Admittedly, COM is kind of confusing. But it's there if you need it.
>
> Mike

Oops...forgot that to mention that I import the sleep function from
the time module in the above code. Sorry about that.

Mike




More information about the Python-list mailing list