简体   繁体   English

使用Python打开只读Excel文件

[英]Open a read-only Excel file using Python

I have a program (zTree) that is writing an Excel file and updating it constantly. 我有一个程序(zTree),该程序正在编写Excel文件并不断对其进行更新。 What I need this Python program to do is read in the data from the Excel file as its updating. 我需要这个Python程序执行的操作是从Excel文件读取数据作为其更新。 The problem that I'm having though is that when I try to read in the data using xlrd, I get the error: 我遇到的问题是,当我尝试使用xlrd读取数据时,出现错误:

    peek = f.read(peeksz)
IO Error: [Errno 13] Permission denied

which comes up because Excel is in read-only mode. 因为Excel处于只读模式而出现。 Is there any way to read in the data of an Excel file in read-only mode using Python? 有什么方法可以使用Python以只读模式读取Excel文件的数据吗?

just tested it on win 7 (64bit), but in this case it works: 刚刚在win 7(64位)上对其进行了测试,但是在这种情况下,它可以正常工作:

import xlrd
workbook = xlrd.open_workbook('C:/User/myaccount/Book1.xls')
worksheet = workbook.sheet_by_name('Sheet1')
print worksheet

could it be, that you are trying to copy it first, or that your python is trying to put a temporary copy of the file in the py-directoy? 可能是您要先复制它,还是您的python试图将文件的临时副本放入py-directoy? - because that would give the IO-Error -因为那样会产生IO错误

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

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