如何使用python打开密码保护的excel文件? [英] How to open a password protected excel file using python?

查看:1345
本文介绍了如何使用python打开密码保护的excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过以前关于这个主题的主题,但是他们没有帮助解决问题。

I looked at the previous threads regarding this topic, but they have not helped solve the problem.

如何用py32com打开写保留的excel文件?

我试图在Excel中打开受密码保护的文件,无需任何用户交互。我在网上搜索,发现这个代码使用win32com.client
当我运行这个,我仍然得到提示输入密码...

I'm trying to open a password protected file in excel without any user interaction. I searched online, and found this code which uses win32com.client When I run this, I still get the prompt to enter the password...

from xlrd import *
import win32com.client
import csv
import sys

xlApp = win32com.client.Dispatch("Excel.Application")
print "Excel library version:", xlApp.Version
filename,password = r"\\HRA\Myfile.xlsx", 'caa team'
xlwb = xlApp.Workbooks.Open(filename, Password=password)


推荐答案

p>在这种情况下,我不认为命名参数有效。所以你必须这样做:

I don't think that named parameters work in this case. So you'd have to do something like:

xlwb = xlApp.Workbooks.Open(filename,False,True,None,password)

xlwb = xlApp.Workbooks.Open(filename, False, True, None, password)

请参阅 http://msdn.microsoft。 com / en-us / library / office / ff194819.aspx 有关Workbooks.Open方法的详细信息。

See http://msdn.microsoft.com/en-us/library/office/ff194819.aspx for details on the Workbooks.Open method.

这篇关于如何使用python打开密码保护的excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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