I'm trying to create an Open Office spreadsheet programmatically but for some reason simply compressing a folder with all the necessary files makes Open Office flag the file as corrupted.
How did I get to this? I started by creating a normal spreadsheet in Open Office with some values in it. After saving I change the extension to .zip and make a copy of the folder. I then compress the second folder using command line zip and change the file extension to .ods. When trying to open the resulting file I get an error from Open Office saying the file is corrupt.
Does Open Office use a special compression algorithm? Doing a "file test.ods" shows it as a compressed zip, so what does Open Office add during the compression routine to make it work?
The shell script worked for me, too :) I had problems zipping back up, after unzipping an odt file. Guess the manifest part was what's missing.
The shell script above did not handle inline pictures/graphics, however, so I made some small adjustments which worked for me (also, the script had a bug in that END_HEREDOC was not on a dedicated line):
This worked for me:
Uncompress the original document file (it's a normal zip file) to some directory:
Modify the uncompressed data.
Create a new odt:
Section 17 Of the OASIS OpenOffice Specification defines how OpenDocument Packages need to be packaged.
Section 17.4 MIME Type Stream reads like this:
I have tried tokland suggestion, but I have founded that LibreOffice 4 require specific order (only for the first ones?):
mimetype
(uncompressed)meta.xml
settings.xml
content.xml
Thumbnails/thumbnail.png
Configurations2/images/Bitmaps/
Configurations2/popupmenu/
Configurations2/toolpanel/
Configurations2/statusbar/
Configurations2/progressbar/
Configurations2/toolbar/
Configurations2/menubar/
Configurations2/accelerator/current.xml
Configurations2/floater/
styles.xml
META-INF/manifest.xml
I create a script to do that folder2od.sh:
I've found some interesting infos here: http://www.jejik.com/articles/2010/03/how_to_correctly_create_odf_documents_using_zip/