read a password protected xls file

T

thomas.steffen75

Hello,
how can I read (and parse) a password protected xls file, perhaps with
the package xlrd?
Thanks for your hints, Thomas
 
J

John Machin

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 ...
www.lexicon.net/sjmachin/xlrd.htm - 15k - Cached - Similar pages -
"""

You'll need a Windows box with Excel installed.
Get the package described here: http://wiki.python.org/moin/Win32All
Install it, do the "makepy" thing [see the docs] to link with the
Excel COM routines.
Ask questions on the mailing list described on
http://mail.python.org/mailman/listinfo/python-win32

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
password.
"""
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

HTH,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top