[python-win32] Having more Excel troubles.

Joe Goldthwaite joe at goldthwaites.com
Wed Aug 25 23:36:26 CEST 2004


Hello Again,

I thought I had all my problems worked out then I ran head on into another
one.  The application I've been trying to develop is Zope based.  I've got
some financial reports that they can browse through using a web interface.
What I'm trying to do is have a link on the page that will download the
report they're viewing into a local Excel worksheet.

I decided to use com because I want the worksheet to have colors, print
settings, formatting, etc. that I already have working in VB.  I've looked
into XML and Pyxlwriter but it looks like a new learning curve compared to
just translating my VB com commands into Python.

I'm using Visual Studio .Net 2003 with Active Python as my development
environment.  When I submit the URL that creates the XL worksheet in
development, it works like a top.  In testing, I've generated 50 different
worksheets without any problems.

When I try to run the same code in Zope I have problems. Under Zope, I take
the submitted URL and create a worksheet that I save to a file.  Then I
return a meta command to redirect the browser to the newly created file
which is downloaded to the users computer. The good news is that it works
perfectly - sometimes. Other times I get this error message;

     Module ExcelReport, line 48, in __init__
     Module win32com.client, line 95, in Dispatch
     Module win32com.client.dynamic, line 91, in _GetGoodDispatchAndUserName
     Module win32com.client.dynamic, line 79, in _GetGoodDispatch
     com_error: (-2147221008, 'CoInitialize has not been called.', None,
None)

I know this is probably a Zope problem but the error message is coming back
from the line; XLApp = Dispatch("Excel.Application").  I'm going to post a
message on the Zope developers list to see if they have any clue.

The really strange thing is that the error seems to be random.  Sometimes it
works, sometimes it doesn't.  I haven't been able to determine any rhyme or
reason to it.  When I restart Zope, it will work one to as many as 10 times.
Then I'll get the error message.  If I keep trying the same URL, it might
eventually work or I may have to restart Zope to get it working again.

Does anyone have any idea as to what's going on here?


Thanks,

Joe Goldthwaite




More information about the Python-win32 mailing list