How to read password protected excel in python

I am 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 loads, but still asks me for the password, I cannot let python enter the password for me.

How am I wrong? Thank!

+1
source share
2 answers

Open uses 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 write protection or protection protected?

There is also a discussion of SO that says this does not work with named parameters. Therefore, try to provide all the default settings

MSDN

+2

,

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

, . .

+2

Source: https://habr.com/ru/post/1569331/


All Articles