[python-win32] Excel win32com newbie question

Jim Steil jim at qlf.com
Fri Oct 6 15:30:48 CEST 2006


Thanks for the response!  I tried your suggestion with the following
results....

>>> import win32com.client
>>> x = win32com.client.gencache.EnsureDispatch("Excel.Application")
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line
536, in EnsureDispatch
    mod = EnsureModule(tla[0], tla[1], tla[3], tla[4],
bForDemand=bForDemand)
  File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line
393, in EnsureModule
    module = GetModuleForTypelib(typelibCLSID, lcid, major, minor)
  File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line
258, in GetModuleForTypelib
    mod = _GetModule(modName)
  File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line
629, in _GetModule
    mod = __import__(mod_name)
  File
"C:\Python24\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-00000
0000046x0x1x5\__init__.py", line 1748
    '{000208C8-0001-0000-C000-000000000046}' : 'IWalls',
	'{000208C9-0001-0000-C000-000000000046}' : 'ITickLabels',
                                                        ^
SyntaxError: invalid syntax
>>>


Any ideas from here?

	-Jim

-----Original Message-----
From: python-win32-bounces+jim=qlf.com at python.org
[mailto:python-win32-bounces+jim=qlf.com at python.org] On Behalf Of Tim
Roberts
Sent: Thursday, October 05, 2006 6:06 PM
To: Python-Win32 List
Subject: Re: [python-win32] Excel win32com newbie question

Jim Steil wrote:

> I've been working this week building some Excel spreadsheets using
> Python and win32com. ...
>
> Possibly my biggest problem is that I can't get my machine to give me
> the Excel constants. Here is the code I'm doing to try to test the
> constants and the error I'm getting back.
>
> from win32com.client import constants, Dispatch
>
> x = constants.xlHAlignRight
>
> Traceback (most recent call last):
>
> File "<input>", line 1, in ?
>
> File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line
> 168, in __getattr__
>
> raise AttributeError, a
>
> AttributeError: xlHAlignRight
>
> I'm hoping there is something obvious that I'm missing. I think I can
> find my way through the rest of my issues if I can just get by this
> constants problem. Thanks for any help you can provide.
>

Did you run "makepy.py" on the Microsoft Excel Object Library? "makepy"
is the one that extracts the constants.

Alternatively, you can replace
x = win32com.client.Dispatch("Excel.Application")
with
x = win32com.client.gencache.EnsureDispatch("Excel.Application")

That runs the "makepy" process, which makes the constants available:

C:\tmp>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
>>> x = win32com.client.Dispatch("Excel.Application")
>>> from win32com.client import constants
>>> constants.xlHAlignRight
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:\apps\python24\lib\site-packages\win32com\client\__init__.py",
line 18, in __getattr__
raise AttributeError, a
AttributeError: xlHAlignRight

C:\tmp>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
>>> x = win32com.client.gencache.EnsureDispatch("Excel.Application")
>>> from win32com.client import constants
>>> constants.xlHAlignRight
-4152
>>>

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32




More information about the Python-win32 mailing list