Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • how to read password protected excel in python

  • How to open write reserved excel file in python with win32com?

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)
like image 275
Schack Avatar asked Oct 18 '13 13:10

Schack


People also ask

How remove password from Excel using Python?

Remove Excel Sheet Protection Password Using Python By now you probably know already how to do this. Simply set the appropriate parameter to False to “unprotect” the sheet, and we don't even need to know the password!

How do I read an XLXS file in Python?

The read_excel() function of pandas is used for reading the xlsx file. This function has used in the script to read the sales. xlsx file. The DataFrame() function has used here to read the content of the xlsx file in the data frame and store the values in the variable named data.


1 Answers

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 http://msdn.microsoft.com/en-us/library/office/ff194819.aspx for details on the Workbooks.Open method.

like image 157
Bjorn Stiel Avatar answered Sep 20 '22 08:09

Bjorn Stiel