openoffice.org - how to create an odt file programmatically with java? -
how can create odt (libreoffice/openoffice writer) file java programmatically? "hello world" example sufficient. looked @ openoffice website documentation wasn't clear.
take @ odfdom - opendocument api
odfdom free opendocument format (odf) library. purpose provide easy common way create, access , manipulate odf files, without requiring detailed knowledge of odf specification. designed provide odf developer community easy lightwork programming api portable object-oriented language.
the current reference implementation written in java.
// create text document standard template (empty documents within jar) odftextdocument odt = odftextdocument.newtextdocument(); // append text end of document. odt.addtext("this first odf test"); // save document odt.save("myfilename.odt");
later
as of writing (2016-02), told these classes deprecated... big time, , odftextdocument
api documentation tells you:
as of release 0.8.8, replaced org.odftoolkit.simple.textdocument in simple api.
this means still include same active .jar file in project, simple-odf-0.8.1-incubating-jar-with-dependencies.jar
, want unpacking following .jar documentation: simple-odf-0.8.1-incubating-javadoc.jar
, rather odfdom-java-0.8.10-incubating-javadoc.jar
.
incidentally, documentation link downloads bunch of jar files inside .zip says "0.6.1"... of stuff inside appears more 0.8.1. have no idea why "as of 0.8.8" in documentation "deprecated" classes: marked deprecated.
the equivalent simple code above then:
odt_doc = org.odftoolkit.simple.textdocument.newtextdocument() para = odt_doc.getparagraphbyindex( 0, false ) para.appendtextcontent( 'stuff , nonsense' ) odt_doc.save( 'myspankingnewfile.odt' )
ps using jython, java should obvious.
Comments
Post a Comment