Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 244
Jacobr365 Avatar asked Dec 29 '14 18:12

Jacobr365


People also ask

How can I open a password protected Excel file?

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.

How do I password protect an Excel file in Linux?

Go to Protect Workbook. Then click on Encrypt with Password. Enter and confirm the password you want.

Can Python manipulate Excel files?

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.


Video Answer


1 Answers

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'
like image 145
Will Avatar answered Oct 23 '22 11:10

Will