Python Forum

Full Version: Access xlsm file that has been open
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I use openpyxl in python 3.6.1 to read/write xlsm file of Excel 2010.
Is there a way to access the file, that has been opened manually, without open it again in code? Thanks.

my code here
I believe you can open an excel file more than once, so long as it's only opened for writing once,
and for good reason. There is no sharing, or locking mechanism, so that makes perfectly food
sense.
If the question is "can I read inside Excel's memory to figure out which file it s currently working with (assuming there is only one...) and do things to it with Python" the answer is no, and anyway if you change anything in the file, Excel won't see it and will overwrite them on exit.

So, why are you trying to do this?
Thank you for your replies. I need to retrieve some data records and display them on something like spreadsheet, and timely update them while displaying. If Excel file no good, is there a way to use python GUI or something to do it? If yes, is there some sample codes for it? thanks again.

I have been using Microsoft Powershell / VBA to do it but feel slow. I was told python is faster than java or C++.
If you are planning on having a graphical display, the wxpython package has a grid widget
see: https://web.cs.wpi.edu/~mebalazs/wxClips/wxc144.htm.

if you want to display excel in python, you can use pandas
see: https://stackoverflow.com/questions/1063...-or-matrix
Thank you for your samples that are very informative.
I found below but not sure how to get gridlines displayed. Is there a way to do that? Thanks

import tkinter
grid = tkinter.Tk()
for r in range(15):
for c in range(10):
tkinter.Label(grid, text='R%s/C%s'%(r,c)).grid(row=r,column=c)
grid.mainloop()
The tkinter grid has nothing to do with displaying a grid. It is a geometry,
and has to do with laying out the widgets in a grid (row, column) format.