Closed lgxcxd closed 1 month ago
xw.apps.add()
should probably not be there. Use this instead:
import xlwings as xw
with xw.App() as app: # <==
print(app.books.active)
xw.apps.add()
should probably not be there. Use this instead:import xlwings as xw with xw.App() as app: # <== print(app.books.active)
Thanks alot! I was learning when to use xw.books.add(), and I realized that you must first establish a workbook (either through code or manually) for this line of code to take effect. Also, when Excel is not running, even after executing xw.apps.add(), running print(xw.apps) still outputs an empty set: Apps([]). However, the established app can print out the PID value. This seems incorrect; after creating an Excel app, the apps collection should have a member.
You're correct, this is a bug. Most likely introduced with the engine refactor. However, I'd consider it more Pythonic anyways to use xw.App()
, so you can work around it.
You're correct, this is a bug. Most likely introduced with the engine refactor. However, I'd consider it more Pythonic anyways to use
xw.App()
, so you can work around it.
I am learning to use xlwings, so I don't want to ignore the information provided on the xlwings official help site, including how to use xw.books.add(). Now, I am more inclined to use wb = xw.Book() to create or link to a workbook.
xw.Book()
should be your default, yes. The only reason you'd use books.add()
would be to open it in a specific app via myapp.books.add()
.
OS (e.g. Windows 10 or macOS Sierra)
windows 11
Versions of xlwings, Excel and Python (e.g. 0.11.8, Office 365, Python 3.7)
0.32.2
Describe your issue (incl. Traceback!)
Include a minimal code sample to reproduce the issue (and attach a sample workbook if required!)