COM and win32 - casting com to string

Steve Holden sholden at holdenweb.com
Wed Oct 3 07:31:29 EDT 2001


"Ignacio Vazquez-Abrams" <ignacio at openservices.net> wrote in message
news:mailman.1002094324.11153.python-list at python.org...
> On Wed, 3 Oct 2001, Paul Brian wrote:
>
> > I am trying to automate excel, and have been relatively successful.
> > I can start up a python com client from win32 extentions and bring up
excel
> > as a server. (I hope I got that the right way round :-)
> >
> > I can then identify "named ranges" in excel (a group of cells that I
> > previously told excel to keep track of)
> >
> > the code:
> >     x = excelAppl.ActiveWorkBook.Names
> >     for namerange in x:
> >         print namerange
> > gives me my two ranges back:
> > =Sheet1!$D$3:$G$3
> > =Sheet1!$D$4:$D$7
> >
> > all I want to do know is split those into the sheet1 and the $D$3....
> >
> > however the two results are not python instances but
> > <COMObject <unknown>>
> >
> > I cannot perform string operations, repr does not help and type() just
tells
> > me they are "instances" - can anyone tell me what I am doing wrong.
> > I expect I am not understanding something about com / win32.
>
> Does str() have any effect?
>
To manipulate the COM objects you get back from Ecel you need to use the
Visual Basic methods, which *are* available (since what you've got back is
an object). If you've got the VBA help installed in Excel try searching for
"Range method" and apllying some of those functions.

never-did-understand-the-Office-object-model-ly y'rs  - steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list