Differences between revisions 1 and 2
Revision 1 as of 2004-01-27 02:06:06
Size: 897
Editor: trinity
Comment:
Revision 2 as of 2004-01-27 13:56:40
Size: 1583
Editor: cache1-1-ffm-vpn
Comment: added "makepy -o filename.py"
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Description =
Line 9: Line 10:
= Solution 1 =
Line 24: Line 26:

= Solution 2 =

That solution was the easier one for py2exe 0.4, but it still works:

{{{
cd \python23\Lib\site-packages\win32com\client
python makepy.py -o {MyProjectDirectory}\OLE_Excel10.py
}}}

within the software change:

{{{
#!python
import win32com.client
o = win32com.client.Dispatch("Excel.Application")
o.Method()
o.property = "New Value"
print o.property
}}}
(taken from M. Hammonds documentation "Quick Start to Client side COM and Python")

to

{{{
#!python
import OLE_Excel10 as Excel
_ec=Excel.constants

o = Excel.Application()
o.Method()
o.property = "New Value"
print o.property
}}}
HAM2004-01-27

Description

Typically when dealing with 3rd party COM libraries (eg. Office), you make use of the constants defined in that library. Once makepy creates the typelib for you, using these constants is normally easy in python. You only need to import win32com.client.constants to access them.

However, since these typelibs aren't really imported, py2exe needs to be told to include them in your setup-script.

Solution 1

Here's how I'm importing the typelib for Excel XP:

setup.py:

 ...
 setup(
        ...,
        options = {"py2exe": {"typelibs": [('{00020813-0000-0000-C000-000000000046}',0,1,4)]}},
        ...
      )

So, as you can see, it's an option in the options dictionary, containing a list of the typelibs you need. Each typelib being represtented as a tuple of (CLSID, LCID, MajorVersion, MinorVersion) - all of which numbers you can find in the typelib file itself.

Solution 2

That solution was the easier one for py2exe 0.4, but it still works:

cd \python23\Lib\site-packages\win32com\client
python makepy.py -o {MyProjectDirectory}\OLE_Excel10.py

within the software change:

   1 import win32com.client
   2 o = win32com.client.Dispatch("Excel.Application")
   3 o.Method()
   4 o.property = "New Value"
   5 print o.property

(taken from M. Hammonds documentation "Quick Start to Client side COM and Python")

to

   1 import OLE_Excel10 as Excel
   2 _ec=Excel.constants
   3 
   4 o = Excel.Application()
   5 o.Method()
   6 o.property = "New Value"
   7 print o.property

HAM2004-01-27

IncludingTypelibs (last edited 2017-11-26 01:33:30 by JimmyRetzlaff)