'Opening two Excel sheets on two separate Excel application instances

I'm very new to python language and xlwings. I just want to accomplish something very simple. I have two excel sheets, a.xlsx and b.xlsx. I know how to open them using the common xlwings Python API via the following xw.Book(r'C:/path/to/a.xlsx') xw.books.open(r'C:/path/to/a.xlsx')

However, when I try to add an excel instance and try to open the excels, I do not know the command structure (object hirearachy) to open them in two independent instance of Ms Excel app. Thanks in advance.



Solution 1:[1]

If you want to open them each in different instances, this should work. Please see the docs under Book, https://docs.xlwings.org/en/stable/api.html#book . Once you do it for the first instance, do the same for the second, with the new instance pid.

import xlwings as xw

>>>app = xw.App() # Create new instance
>>>app.pid # Get pid to point at.
30332
>>>xw.apps[30332].books.open(r'C:/path/to/a.xlsx')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eric M