[python-win32] Having more Excel troubles.
Joe Goldthwaite
joe at goldthwaites.com
Fri Aug 27 19:50:56 CEST 2004
Hi Mark,
I didn't expect you to reply. I checked the archive and see that you're
very active on the list. That's great!
I changed from Dispatch() to DispatchEx() since that sounds like the better
choice for my application. It didn't fix the problem though. The
pythoncom.CoInitialize() seems to have done the trick.
Thank you very much for your help. And thanks all your work on the Win32
stuff. I ordered a copy of your book. Thanks for taking the time to write
it. I'm still new in the open source arena and one of the biggest
challenges is figuring how to get this stuff to work.
Joe Goldthwaite
-----Original Message-----
From: Mark Hammond [mailto:mhammond at skippinet.com.au]
Sent: Wednesday, August 25, 2004 9:07 PM
To: joe at goldthwaites.com; python-win32 at python.org
Subject: RE: [python-win32] Having more Excel troubles.
> _GetGoodDispatchAndUserName
> Module win32com.client.dynamic, line 79, in _GetGoodDispatch
> com_error: (-2147221008, 'CoInitialize has not been
> called.', None,
> None)
That error means "CoInitialize has not been called *on this thread*". Try
calling pythoncom.CoInitialize() at the top of your script - it should not
throw an error if it has already been called.
I'm not sure this is a great idea though - you would be better off creating
your own thread that processes *all* excel requests, possibly using the
queue module. Consider what will happen when 2 people try and perform the
conversion at the same time. By using DispatchEx() you can force each
thread to get its own Excel, but I'm not sure that is a great idea even
then.
Mark
More information about the Python-win32
mailing list