read a password protected xls file

Discussion in 'Python' started by thomas.steffen75@googlemail.com, Jan 12, 2009.

  1. Guest

    Hello,
    how can I read (and parse) a password protected xls file, perhaps with
    the package xlrd?
    Thanks for your hints, Thomas
    , Jan 12, 2009
    #1
    1. Advertising

  2. John Machin Guest

    On Jan 13, 3:35 am, 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
    John Machin, Jan 13, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    2
    Views:
    557
    Andreas Klemt
    Jul 5, 2003
  2. AAaron123
    Replies:
    2
    Views:
    2,153
    AAaron123
    Jan 16, 2009
  3. AAaron123
    Replies:
    1
    Views:
    1,335
    Oriane
    Jan 16, 2009
  4. cj2
    Replies:
    6
    Views:
    389
    Allen Chen [MSFT]
    Mar 18, 2009
Loading...

Share This Page