Python <=> Excel question

Magnus Lycka lycka at carmen.se
Tue Oct 4 08:46:58 EDT 2005


Gerry Blais wrote:
> Newbie questions:
> 
> Suppose abc.xls has sheets a, b, c.
> 
> How can I find, in Python, the sheet names?
> 
> Given a sheet name, how can I export the sheet as a csv file?
> 
> Finally, how can I, in Python, make a .txt version of a Word document?

I think Google will help you to find plenty of solutions to these
things. It's probably better to try something out and come here if
you're really stuck. You might want to start with this...
http://www.markcarter.me.uk/computing/python/excel.html

In general, it's typically helpful to use the VBA editor in Excel
to discover what the object model looks like, what methods there are
and what parameters they take etc. Then you can use this from Python
via win32com.client instead. You need the win32all extensions for
Python (or something like ctypes, but I never used that). ActivePython
contains win32all by default, but it's simple to install win32all for
a vanilla Python installation. It's reachable through the normal
Python download page (or via Google of course).

I'm sure some experimentation based on these hints can solve your
problem. It takes some time to understand the object model, and
how it maps to the Python interface, but it's not rocket science.

This book is really helpful for understanding how to use Python with
e.g. Word and Excel:
http://www.amazon.com/exec/obidos/tg/detail/-/1565926218



More information about the Python-list mailing list