Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > read a password protected xls file

Reply
Thread Tools

read a password protected xls file

 
 
thomas.steffen75@googlemail.com
Guest
Posts: n/a
 
      01-12-2009
Hello,
how can I read (and parse) a password protected xls file, perhaps with
the package xlrd?
Thanks for your hints, Thomas
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      01-13-2009
On Jan 13, 3:35*am, (E-Mail Removed) 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 ...
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieving a file from a password protected site cj2 ASP .Net 6 03-18-2009 07:15 AM
Generate pdf file with password protected. Prabu Jayaraman Ruby 2 03-12-2009 02:11 PM
Change a users password without knowing the old password nor the answer to the password question AAaron123 ASP .Net 1 01-16-2009 02:56 PM
Changing a users password without knowing the old password nor the answer to the password question AAaron123 ASP .Net 2 01-16-2009 02:08 PM
Difference between "Protected WithEvents myClassName" And "Protected myClassName" ? Andreas Klemt ASP .Net 2 07-05-2003 12:51 AM



Advertisments