COM and win32 - casting com to string
tim.golden at iname.com
Wed Oct 3 16:32:36 CEST 2001
"Paul Brian" <pbrian at demon.net> wrote in message news:<1002093124.20881.0.nnrp-14.c2de2503 at news.demon.co.uk>...
> the code:
> x = excelAppl.ActiveWorkBook.Names
> for namerange in x:
> print namerange
> gives me my two ranges back:
> 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 don't claim to be an expert here, but the following two things might
help you out. You probably need both, tho' I don't have time to check
at the moment.
1) Run gen_py against the Excel application library (from Tools > COM
Makepy if you're running ActivePython, directly otherwise). This will
generate a .py file containing the COM interface to Excel which will
let Python give slightly more useful information such as the name of
the class whose instance you are listing.
2) Use the RefersTo property of the items in the namerange:
>>> x = excelAppl.ActiveWorkbook.Names
>>> true_range = x.RefersTo
>>> print true_range
I'm using Excel 2000 which may make some difference to names
(specifically, I had to use "ActiveWorkbook" (lowercase b) rather than
"ActiveWorkBook" as in your example. I hope, tho', that the technique
More information about the Python-list