read a password protected xls file

John Machin sjmachin at
Tue Jan 13 01:55:21 CET 2009

On Jan 13, 3:35 am, thomas.steffe... at wrote:
> Hello,
> how can I read (and parse) a password protected xls file, perhaps with
> the package xlrd?
> Thanks for your hints, Thomas

Perhaps not with xlrd. google("xlrd"); *first* hit displayed:
Lingfo - xlrd extension
11 Jun 2007 ... Exclusions: xlrd will not attempt to decode password-
protected (encrypted) files . Otherwise, it will safely and reliably
ignore any of these ... - 15k - Cached - Similar pages -

You'll need a Windows box with Excel installed.
Get the package described here:
Install it, do the "makepy" thing [see the docs] to link with the
Excel COM routines.
Ask questions on the mailing list described on

Sample code:

import sys
import win32com.client
xlApp = win32com.client.Dispatch("Excel.Application")
print "Excel library version:", xlApp.Version
filename, password = sys.argv[1:3]
# filename should be absolute path e.g. r'C:\myfiles\foo.xls'
xlwb = xlApp.Workbooks.Open(filename, Password=password)
# xlwb = xlApp.Workbooks.Open(filename)
""" From the MS VBA Help for Excel 2003:
Password   Optional Variant. A string that contains the password
required to open a protected workbook. If this argument is omitted and
the workbook requires a password, the user is prompted for the
print repr(xlwb)
print xlwb.FullName
xlws = xlwb.Sheets(1) # counts from 1, not from 0
print repr(xlws)
print xlws.Name
print xlws.Cells(1, 1) # that's A1


More information about the Python-list mailing list