By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Separating win32com automation instances?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.