Remove protection of OpenOffice/LibreOffice spreadsheets

Sjouke and I just ran into a minor hitch with a spreadsheet: some cells were protected, and in the new Ubuntu / Open/LibreOffice version they just looked plain wrong.
How to fix this?
Turns out that protection isn’t that hard to break. In a nutshell, an .ODS file is very much like an EPUB file — it’s also a ZIPped file which also contains a structure with a mimetypes file and a content.xml file.

To remove protection, edit contents.xml and change the attribute *protected="true" to say false. Rezip the file in the correct way, that is: store mimetype uncompressed as the first file, the rest doesn't really matter. Et voila, you have removed protection!

In a nutshell:

mkdir tmp
cd tmp
unzip ../FILE.ods
sed 's/protection="true/protection="false/g' content.xml c2.xml
mv c2.xml content.xml
zip -0X ../FILE-unprotected.ods mimetype
zip -r9 ../FILE-unprotected.ods * -x mimetype

Comments are closed.