Python, COM & Excel

Mike Brenner mikeb at MITRE.ORG
Tue Jan 21 17:42:23 EST 2003


DP > I'm doing some work with Python, & COM integration (win32all v. 1.52
> installed with Pthon 2.2.2). I'm having a difficult time getting
> started. Some of the functions/objects I expect will work don't, others
> work in unexpected ways. I'd very much appreciate pointers, sample
> scripts, etc. from individuals who have had better luck with Python &
> Excel integration. I'm working primarily with Excel 2000 and MS Word. I
> hope to be able to figure things out myself later, pointers will be
> appreciated.


We all would like some working scripts to do the hard stuff, although
the easy stuff is in the examples that come with Python. Most of
the problem is that COM is very slow and the object model
is very undocumented and incomplete, especially for the lesser
used options. However, be of good cheer, because every other 
Office product is even less documented than Excel (the least
documented being Microsoft Project).

What is needed is mostly: for each action you can take in 
Excel, here is where it is in the object model.

I will share what I have learned. Do you have any specific
questions.


Thomas > There is a different way to 
> combine MS-Office and Python: XML.
> Write yourself a small SAX parser 
> and change the things you want to
> change and then write it back to XML. 

Hi Tom, 

I understand that xml goes well with Python; 
however, I don't understand how xml integrates
well with MS-Office, particularly EXCEL.

If I have an Excel Spreadsheet, are you saying
that there is a way to get it into XML and 
that there is away to get that XML back into EXCEL?

I would like to know how to do that, particularly
with merged cells, cells with different borders
from their neighbors, filters, and macros.

(Note that POI, the Jakarta Java interface that reads excel
files into Java, does not do so well on merged cells, 
and borders are notoriously undocumented, yet
and important means of adding a dimension onto 
a spreadsheet. It would be great if there were
a means of going back and forth between Excel and
XML, because then Python would have the full power
of EXCEL. Of course, I realize that I can read in 
a csv file with simple numbers and no attributes,
but that is not a very complete "integration" with
Excel.)

Mike






More information about the Python-list mailing list