Working with Password Protected Excel Sheets in Python on Linux
Asked Answered
F

1

8

The problem is pretty simple. Every week I receive a bunch of password protected excel files. I have to parse through them and write certain parts to a new file using Python. I am given the password for the files.

This was simple to handle when this was being done on Windows and I could just import win32com and use client.Dispatch. But we are now moving all our code to linux so no more win32com for me.

Is there a way to open and read data from a password protected excel sheet in python on linux?

I have been searching for simple way to open a password protected excel file but no luck. I also tried finding a way to just remove the password protection so I can use xlrd like I would on a file that is not password protected but no luck going that route either.

Any help would be most appreciated.

Farrish answered 29/12, 2014 at 18:0 Comment(4)
This looks like it could work for you #19451337Courland
@perfectvid2012: No it doesn't. The whole point is to find a solution that does NOT use win32com (or anything else Windows-specific).Bagwell
Hmm? Now I am confused.Farrish
I have no options to undelete anything. All I see is the one answer that is marked as the answer.Farrish
B
6

with libreoffice and unoconv

unoconv --password='p4ssw0rd' -f csv  protectedFile.xls

and then parse the csv file. Or export to another xls if you need the formatting or want to torture yourself

N.B. Edited after accepted. (--password is the correct switch, not -p, as noted by @enharmonic)

I've recently had an easier time using xlsxunpass

java -jar ./xlsxunpass.jar protected.xlsx unprotected.xlsx 'p4ssw0rd'
Baldric answered 2/2, 2016 at 21:1 Comment(8)
What if my .xlsx have multiple sheetsOrestes
try writing to another format supporting sheets. e.g. unoconv -p p4ssw0rd -f xlsx protectedFile.xlsBaldric
doesn't run (with error)? or is still password protected? if you already have xlsx, try going to xls unoconv -p p4ssw0rd -f xls protectedFile.xlsx or ods unoconv -p p4ssw0rd -f ods protectedFile.xlsxBaldric
I'm getting this error 'Error: Unable to connect or start own listener. Aborting.' . Any idea why?Thyrse
@Thyrse I don't think the -p option is for passwords; docs say it is for specifying a port. "-p, --port Port to listen on (as listener) or to connect to (as client). Default port is '2002'." linux.die.net/man/1/unoconvCrore
@Crore i updated the answer. I wonder if this was a change in the command switches or if the answer never actually workedBaldric
@Baldric I can unlock the protected file using xlsxunpass package but not unoconv. I'm still getting the same error using unoconv.Thyrse
xlsxunpass is the only thing that has worked for me so far; thanks for your work on it, @Will!Crore

© 2022 - 2024 — McMap. All rights reserved.