[Zope] Using win32com in Zope
Ashley Lloyd
ashleylloyd@hotmail.com
Fri, 20 Jun 2003 13:43:08 +0100
Thanks very much to Alexis Roda for this one.
Problem solved. For anyone else who gets the same problem, it seemed to be
with the installation (or lack of it) of win32com for Zope.
The solution I used was based on:
http://effbot.org/zone/python-register.htm
Although I didn't follow those instructions exactly, it did give me the
registry keys to change, then re-install win32com, making it install for the
Zope python, rather than the stand-alone Python.
Thanks again to Alexis
From: "Ashley Lloyd" <ashleylloyd@hotmail.com>
To: zope@zope.org
Subject: [Zope] Using win32com in Zope
Date: Wed, 18 Jun 2003 11:55:37 +0100
I have been trying to write to Excel from Zope, using win32com.
If I try the following in python, it works fine:
>>>from win32com.client import Dispatch
>>>o=Dispatch("Excel.Application")
>>>
>>>o.Visible=1
>>>o.Workbooks.Add()
<COMObject Add>
>>>o.Cells(1,1).Value = "Hello"
>>>o.Cells(1,2).Value = "World"
However, attempting to do this with an external method from within Zope
(having done my best to get all of the files it depends on copied over into
Zope sub-directories in bin/lib):
def launchExcel(self):
from win32com.client import Dispatch
o=Dispatch("Excel.Application")
o.Visible=1
o.Workbooks.Add()
o.Cells(1,1).Value = "Hello"
o.Cells(1,2).Value = "World"
I get the following error when attempting to test the external method:
--------------------------------------------------------------------------------------------------------------------------------
Error Type ImportError
Error Value cannot import name Dispatch
Error Trace Traceback (innermost last):
File C:\PROGRA~1\ZopeSite\lib\python\ZPublisher\Publish.py, line 98, in
publish
File C:\PROGRA~1\ZopeSite\lib\python\ZPublisher\mapply.py, line 88, in
mapply
(Object: launchExcel)
File C:\PROGRA~1\ZopeSite\lib\python\ZPublisher\Publish.py, line 39, in
call_object
(Object: launchExcel)
File
C:\PROGRA~1\ZopeSite\lib\python\Products\ExternalMethod\ExternalMethod.py,
line 205, in __call__
(Object: launchExcel)
(Info: ((), {}, None))
File C:\PROGRA~1\ZopeSite\Extensions\excelstuff.py, line 11, in launchExcel
(Object: Excel)
ImportError: cannot import name Dispatch
--------------------------------------------------------------------------------------------------------------------------------
Dispatch is defined in win32com/client/__init__.py:
def Dispatch(dispatch, userName = None, resultCLSID = None, typeinfo = None,
UnicodeToString=NeedUnicodeConversions, clsctx = pythoncom.CLSCTX_SERVER):
"""Creates a Dispatch based COM object.
"""
dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo,
UnicodeToString, clsctx)
Can anyone point me in the right direction here?
TIA
Ashley
_________________________________________________________________
Hotmail messages direct to your mobile phone http://www.msn.co.uk/msnmobile
_______________________________________________
Zope maillist - Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection
http://www.msn.co.uk/specials/btbroadband