470,835 Members | 1,939 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,835 developers. It's quick & easy.

Separating win32com automation instances?

I am investigating a web-based app wherein I wanted to provide html
form frontends to an Excel spreadsheet sitting on a MS Windows server;
with each authenticated HTTP user having thier own "invisible" copy of
the spreadsheet changeable via form POST via COM automation object
(via Python) - then after recalculating - present the spreadsheet
results in HTML. The whole idea to 1: isolate the user from having to
have Excel, and 2: avoiding rewriting the hundreds of Excel formulas
in a CGI.

HTML FORM -> POST -> Python win32com -> Spreadsheet -> Recalc -> HTML

Now the problem is that win32com.client.Dispatch apparently does not
play well with other Dispatch instances.

If I have two instances of Python running, and Dispatch two instances
of ("Excel.Application"), I find that when I close one workbook, they
are all closed.

eg:
Python instance 1 in DOS window 1:

from win32com.client import Dispatch
x1 = Dispatch("Excel.Application")
x1.workbooks.open("workbook1.xls")
Python instance 2 in DOS window 2:

from win32com.client import Dispatch
x2 = Dispatch("Excel.Application")
x2.workbooks.open("workbook2.xls")
x2.workbooks.close("workbook2.xls")

Guess what? Closing x2 also closes x1.

How do I get around this? I'm running this test from two DOS prompts.
Also any changes I make using x2 (like switching the sheet) appear in
the x1 instance.

Does DCOM resolve this; is this a failure with Excel; or is it how
win32com works; or is it just a COM problem?

TIA,
Patrick Price
Jul 18 '05 #1
1 2876
win32com.client.DispatchEx will create a new instance even if you already
have an instance of Excel running.
Roger

"Patrick" <jp@moment.net> wrote in message
news:81**************************@posting.google.c om...
I am investigating a web-based app wherein I wanted to provide html
form frontends to an Excel spreadsheet sitting on a MS Windows server;
with each authenticated HTTP user having thier own "invisible" copy of
the spreadsheet changeable via form POST via COM automation object
(via Python) - then after recalculating - present the spreadsheet
results in HTML. The whole idea to 1: isolate the user from having to
have Excel, and 2: avoiding rewriting the hundreds of Excel formulas
in a CGI.

HTML FORM -> POST -> Python win32com -> Spreadsheet -> Recalc -> HTML

Now the problem is that win32com.client.Dispatch apparently does not
play well with other Dispatch instances.

If I have two instances of Python running, and Dispatch two instances
of ("Excel.Application"), I find that when I close one workbook, they
are all closed.

eg:
Python instance 1 in DOS window 1:

from win32com.client import Dispatch
x1 = Dispatch("Excel.Application")
x1.workbooks.open("workbook1.xls")
Python instance 2 in DOS window 2:

from win32com.client import Dispatch
x2 = Dispatch("Excel.Application")
x2.workbooks.open("workbook2.xls")
x2.workbooks.close("workbook2.xls")

Guess what? Closing x2 also closes x1.

How do I get around this? I'm running this test from two DOS prompts.
Also any changes I make using x2 (like switching the sheet) appear in
the x1 instance.

Does DCOM resolve this; is this a failure with Excel; or is it how
win32com works; or is it just a COM problem?

TIA,
Patrick Price

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by It's me | last post: by
6 posts views Thread by Chris Curvey | last post: by
5 posts views Thread by Chris | last post: by
25 posts views Thread by Neil Ginsberg | last post: by
12 posts views Thread by Cheval | last post: by
17 posts views Thread by Mansi | last post: by
1 post views Thread by Roland | last post: by
2 posts views Thread by ago | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.