Search code examples
pythonexcelwin32compythoncom

how do I open read-only excel from python using win32com


I need to open an xls file from python using win32com as read-only and I seem not be getting the effect I desire

Here is what I do:

import win32com

xl = win32com.client.Dispatch('Excel.Application')
wb = xl.Workbooks.Open(file_path, ReadOnly=1) # 1 is for readonly

The workbook opens and data shows; however, the file is not opened as read-only.
per MSDN argument signature should trigger read-only effect but it does not.

Anyone had to deal with similar problem before?


Solution

  • ReadyOnly is a third parameter according to the documentation. Pass None for the UpdateLinks and True for ReadyOnly.

    wb = xl.Workbooks.Open(file_path, None, True)