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.
All you have to do is open the desired workbook and click on the Unprotect Sheet, which will remove the password. To change the password, click on Protect Workbook and type and confirm the new password.
Go to Protect Workbook. Then click on Encrypt with Password. Enter and confirm the password you want.
Openpyxl is a Python library that provides various methods to interact with Excel Files using Python. It allows operations like reading, writing, arithmetic operations, plotting graphs, etc.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With