JohnFayt
JohnFayt

Reputation: 105

Opening ExcelFiles Read-only with Xlwings

I've started looking at xlwings for my excel manipulation as the power and speed of python is much different then VBA for what I am hoping to do. (or so I am told)

Reading through some of the xlwings documentation I couldn't see if there was a way to open an excel file as read-only. Sometime the file I want to open and either open by another application or user, so I cannot access the file because it is trying to open as read-write.

Is there a way with xlwings or another python library that I can open an file in read-only mode, read information from particular ranges, then close the file?

Upvotes: 0

Views: 3647

Answers (1)

fpes
fpes

Reputation: 974

What about making a copy of the file, reading that copy, then deleting that copy after? Alternatively, if you use openpyxl, you dont need to "open" the file since you are reading the xml metadata of excel.

import openpyxl as xl
workbook = xl.load_workbook('path/to/file.xls')
worksheet = workbook.get_sheet_by_name('worksheetname')
cell = worksheet.cell('A1')

All these should work without needing to actually open the file.

Upvotes: 1

Related Questions