I want to be able to read the Excel file in Python, keep the Python script running, doing something else after the reading is complete, and be able to edit the Excel file in another process in the meantime. I am using python 2.7 and openpyxl.
Currently it looks like this:
from openpyxl import load_workbook def get_excel_data(): OESwb = load_workbook(filename = OESconfigFile, data_only=True, read_only=True) ws = OESwb.get_sheet_by_name('MC01') aValue = ws['A1'].value return aValue val = get_excel_data()
After starting the function, the Excel file is still locked to access other processes (it gives the error "file name" is currently being used. Try again later "), even if I do not want to read it in Python anymore.
How to close a file from my script? I tried OESwb.close (), but it gives the error “The object“ Workbook ”does not have the attribute“ close. ”I found this post , but it does not seem to help.
EDIT: It seems OESwb.save ('filename.xlsx') works, but only if read_only = False. However, it would be ideal to be able to close the file and still be in readonly mode. This seems to be a bug with openpyxl, as it should close the file after load_workbook has finished loading.
source share