如何在Python中读取受密码保护的Excel
我是Python编程新手,我正在尝试使用Python读取受密码保护的文件,代码如下所示:
import sys
import win32com.client
xlApp = win32com.client.Dispatch("Excel.Application")
print "Excel library version:", xlApp.Version
filename,password = 'C:\myfiles\foo.xls', 'qwerty12'
xlwb = xlApp.Workbooks.Open(filename, Password=password)
但是然后加载了xls文件但仍然提示我提供密码,我不能让Python输入我的密码。
我做错了什么?谢谢!
I'm new to python programming, and I am trying to read a password protected file using python, the code is shown below:
import sys
import win32com.client
xlApp = win32com.client.Dispatch("Excel.Application")
print "Excel library version:", xlApp.Version
filename,password = 'C:\myfiles\foo.xls', 'qwerty12'
xlwb = xlApp.Workbooks.Open(filename, Password=password)
But then the xls file is loaded but still prompt me to provide the password, I can't let python to enter the password for me.
What have I done wrong? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Open 采用两种类型的密码,即:
那么在你的情况下,它是写保护还是打开保护?
另外还有一个关于 SO 的讨论说这不适用于命名参数,因此请尝试为所有参数值提供默认值
默认值记录在 MSDN
Open takes two types of password, namely:
So in your case , is it write protected or protection on open?
Also there is a discussion on SO that says that this does not work with named parameters, So try providing all parameter values with the defaults
Default values are documented in MSDN
使用它打开受密码保护的文件
xlwb = xlApp.Workbooks.Open(filename, False, True, None, password)
我希望这有效。这对我有用。
Use this to open password protected file
xlwb = xlApp.Workbooks.Open(filename, False, True, None, password)
I hope this works. It worked for me.