How to open a password protected excel file using python?

Posted on

Question :

How to open a password protected excel file using python?

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

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"\HRAMyfile.xlsx", 'caa team'
xlwb = xlApp.Workbooks.Open(filename, Password=password)
Asked By: Schack


Answer #1:

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)

See for details on the Workbooks.Open method.

Answered By: Bjorn Stiel

Answer #2:

If your file size is small, you can probably save that as “.csv”.
and then read

It worked for me 🙂

Answered By: GpandaM

Answer #3:

Openpyxl Package works if you are using linux system. You can use secure the file by setting up a password and open the file using the same password.

For more info:

Answered By: Raj

Leave a Reply

Your email address will not be published. Required fields are marked *