[Zope] Using win32com in Zope
Ashley Lloyd
ashleylloyd@hotmail.com
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