Separating win32com automation instances?

P

Patrick

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
 
R

Roger Upole

win32com.client.DispatchEx will create a new instance even if you already
have an instance of Excel running.
Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top