Separating win32com automation instances?

Roger Upole rupole at hotmail.com
Sat Jul 10 15:54:58 EDT 2004


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

"Patrick" <jp at moment.net> wrote in message
news:81facfe9.0407101118.596149ee at posting.google.com...
> 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





More information about the Python-list mailing list