modify calc dynamically with java

Hi,

I want to modify libreoffice calc (ods) files. I have seen that within the ods
(a zip file) there is content.xml file that contains values. I have tried to change it
and I can change the calc. Sometime formula are not update because there are
"cached values" within the cell. Removing this values (xml attributes) formula are
recalulated. Quite the same with charts.

Is this a good way or there are better ways? There is another "better way" to make calc to
recalculate formula or redraw charts?
It better a library to do this? In case some raccomandation for java?

Thanks in advance for any help!

Davide

Hello Davide,

With the right tools this works very fine actually. It took me some time to figure out which tool to use, but now I use the well designed and well working "Apache ODF Toolkit" here: https://incubator.apache.org/odftoolkit/
It's still in "incubating mode", but I didn't encounter any grave problems so far.

The ODF Toolkit is relatively small, pure Java bundle consisting of two parts: "ODFDOM" and "Simple API". The first one does the more complex low-level work, while the second ones makes it all very high-level for us normal users.

There's some fine examples on the Apache website, too, which should get you going in a short time. Basically you only need to use the Simple-API in order to open some Opendocument file (Writer, Calc, or the others), then you can insert, modify, delete cells, rows, culumns, paragraphs etc in your .odt or .ods file, and then save the result as file. It's a great tool.

The most recent version is 0.61 (summer 2014) but it needs some external JAR which I couldn't find so far, so I'm using version 0.5 (2013) which contains any needed JARs in one Zip file. Version 0.61's bug fixes and new futures aren't that critical for my purposes yet, but in case you would find out where to get the needed external JAR(s) for the 0.61 version, please tell so! Thanks.

P.S. Just in case your Java programs needs to export the resulting .odt or .ods file to a PDF file, too, I can only recommend to directly call from within Java the Libreoffice executable via Java's ProcessBuilder class, i.e. "libreoffice|soffice--convert-to pdf", but skip the UNO API which didn't work (for me).

Good luck and enjoy your Java programming!

Aurelius

Nearly; also v0.5 needs two external JARs which are referenced however on the web-page (I think) and downloadable from the provided links. It's these two:

– xercesImpl.jar
– xml-apis.jar

So in the end you need these four JARs to work with the ODF-Toolkit v0.5 version:
– odfdom-0.8.8.jar
– simple-odf-0.7.jar
– xercesImpl.jar
– xml-apis.jar

Aurelius