如何在python中读取受密码保护的Excel [英] how to read password protected excel in python

查看:1042
本文介绍了如何在python中读取受密码保护的Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python编程的新手,我正尝试使用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)

但是随后加载了xls文件,但仍然提示我提供密码,我不能让python为我输入密码.

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.

我做错了什么?谢谢!

推荐答案

打开需要两种类型的密码,即:

Open takes two types of password, namely:

Password: password required to open a protected workbook.
WriteResPassword : password required to write to a write-reserved workbook

那么在您的情况下,它是写保护还是打开保护?

So in your case , is it write protected or protection on open?

在SO上也有讨论,说这不适用于命名参数,因此请尝试为所有参数值提供默认值

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

默认值记录在MSDN中

Default values are documented in MSDN

这篇关于如何在python中读取受密码保护的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆