Jacobr365
Jacobr365

Reputation: 846

Working with Password Protected Excel Sheets in Python on Linux

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.

Upvotes: 8

Views: 7256

Answers (1)

Will
Will

Reputation: 1323

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'

Upvotes: 6

Related Questions