简体   繁体   English

如何使用win32com从python打开只读Excel

[英]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 我需要使用win32com以只读方式从python打开xls文件,但似乎没有得到我想要的效果

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. 每个MSDN参数签名应触发只读效果,但不会触发。

Anyone had to deal with similar problem before? 有人曾经处理过类似的问题吗?

ReadyOnly is a third parameter according to the documentation . 根据文档, ReadyOnly是第三个参数。 Pass None for the UpdateLinks and True for ReadyOnly . 对于UpdateLinks ,不传递None ;对于ReadyOnly ,则传递True。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM