Fill your text document

A powerfull templating facility is included in jOpenDocument.

You start by creating a template file, directly in OpenOffice, with the help of the jOpenDocument AddOn.

It lets you quickly insert all the grey and green spans you see below.


You start by creating a template. You can then define values that you need in you document. Either by using setField(), or by using showParagraph()/hideParagraph(). Finally you just call saveAs().

  File templateFile = new File("template/test.odt");
  File outFile = new File("out.odt");
  // Load the template.
  // Java 5 users will have to use RhinoFileTemplate instead
  JavaScriptFileTemplate template = new JavaScriptFileTemplate(templateFile);

  // Fill with sample values.
  template.setField("toto""value set using setField()");
  List<Map<String, String>> months = new ArrayList<Map<String, String>>();
  template.setField("months", months);


  // Save to file.

  // Open the document with !;

The final document will look like:

filled template

If you want to know more about templates, look at the package org.jopendocument.dom.template