...
it's not itunes, it's excel.

Traceback (most recent call last):
  File "D:\Documents and Settings\beal-mat\Bureau\_Books\ExcelVersion.py", line 22, in <module>
    excel = cominterface.Application()

Mathieu


On Thu, Jul 12, 2012 at 4:40 PM, Mathieu BEAL <mathieu.beal@gmail.com> wrote:
The link from Harald solved my problem.

The firsts steps are ok:
  - create a Excel2003 file with makepy.py,
  - etc.

import win32com.client

from win32com.client import gencache

from types import ClassType

from win32com.client import EventsProxy, _event_setattr_

win32com.client.gencache.is_readonly = False


import Excel2003 as cominterface

class ExcelEvents:
   def OnSheetBeforeDoubleClick(self, Sh, Target, Cancel)
   def OnWorkbookBeforeClose(self, Sh, Target)

excelapp = cominterface.Application()

rClass = ClassType("COMEventClass", (excelapp.__class__, excelapp.default_source, ExcelEvents), {'__setattr__': _event_setattr_})

instance = rClass(excelapp._oleobj_)

excelapp.default_source.__init__(instance, instance)

#ItunesEvents.__init__(instance) #Uncomment this line if your events class has __init__.

excelapp = EventsProxy(instance)

excelapp.Visible = 1

wb= excelapp.Workbooks.Open(myfilexls)

sleep(5)

excelapp.Quit()


The previous problem : Excel2003 didn't have DispatchWithEvents

To manage with various excel version, I don't know why but the import works with Excel2010.py, even if I have Excel2003 on my computer.
With wrong 'import Excel2003 as cominterface', the excelapp = cominterface.Application() fail.

Traceback (most recent call last):
  File "D:\Documents and Settings\beal-mat\Bureau\_Books\ExcelVersion.py", line 22, in <module>
    itunes= cominterface.Application()
  File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 420, in __init__
    oobj = pythoncom.new(self.CLSID)
pywintypes.com_error: (-2147221164, 'Classe non enregistr\xe9e', None, None)

Mathieu


On Thu, Jul 12, 2012 at 2:47 PM, Michael Haider <Michael.Haider@hofstaedtler.com> wrote:
I had the same Problem with Word...
 
in the setup I excluded the win32com.gen_py
"OPTIONS = {"py2exe": {
               "compressed": 1,
               "optimize": 0,
      "bundle_files": 1,
               'dll_excludes': [ "mswsock.dll", "powrprof.dll", "MSVCP90.dll" ],
               "excludes": "win32com.gen_py",
 
 
and when createing the Wordapp:
 
win32com.client.gencache.is_readonly=False
win32com.client.gencache.GetGeneratePath()
self.Wordapp = win32com.client.DispatchWithEvents("Word.Application",WordEvents)
 
 
Michael
 

>>> "Massa, Harald Armin" <chef@ghum.de> 12.07.2012 14:01 >>>
Mathieu,

Good news, with Excel2003.py import the dispatch function in win32com.client works for both Excels.

Bad news, I have to use the DispatchWithEvents function with is not in Excel2003.py/Excel2010.py.

I'm not sure the problem is still with py2exe, but do you have any idea to solve the problem ? I mean, successfully import DispatchWithEvents


That may provide the solution. Something arount importing EventsProxy

Best wishes,

Harald
--

GHUM GmbH
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607

Amtsgericht Stuttgart, HRB 734971



This message and any attachment are confidential and may be
privileged or otherwise protected from disclosure.  If you are not
the intended recipient, please telephone or email the sender and
delete this message and any attachment from your system.  If you
are not the intended recipient you must not copy this message or
attachment or disclose the contents to any other person.