简体   繁体   中英

Is there a way (in java) to generate human editable Microsoft Word documents from human readable template?

I am searching for a way for my Java application to generate Word document using some kind of Template (the data for the document will be provided by the application) Here are the requirements : - The template should be editable for a non-developper human being. Creating a Jasper template using the adequate tool or editing a Word document with some kind of templating language is compliant. Asking for editing the xml file of the document is not - The results should be easily editable for a human being, using Microsoft Word. For example, the document generated by Jasper or Birt is not compliant, as the table layout prevent any easy edition.

For the moment, I looked at the following solutions, finding no one which match the two requirements :

  • Jasper. The document generated are not easily edited
  • Birt. Same Problem
  • Generating the xml using a template motor (velocity, Freemarker). I cannot ask for the final client to edit this kind of XML file...

You can check out Templater. It has pretty good demo page .

Disclamer: I'm the author.

LibreOffice

LibreOffice is an open-source implementation of an app suite similar to Microsoft Office. Besides supporting the standardized OpenDocument format, it also reads and writes Microsoft Office formats.

LibreOffice offers a Java API . So you may be able to programmatically create documents from a template.

In the past we've done something similar, modifying a document with search-and-replace and document-variables.

Apache Poi

Apache Poi is an open-source library for reading and writing Microsoft Office compatible documents.

I don't know its details but you might take a look.

JODReports (open source) and Docmosis (commercial) are designed to use normal/human-managed documents as templates (Word, OpenOffice, etc), merge in your data and return editable documents, PDFs etc. Please note I work for Docmosis.

Both JODReports and Docmosis provide a Java API.

If you are interested in automating Open Office or Libre Office directly (as mentioned in Basil's answer), this blog about converting Doc to Pdf will give you a quick-start to:

  1. load a doc file as a template
  2. search and replace
  3. export to file (pdf in the example)

To change the output format to Doc instead of PDF:

 propertyValues[1].Value = "writer_pdf_Export";

to

 propertyValues[1].Value = "MS Word 97";

I hope that helps.

Was searching for this kind of solution as well, and I found XDocReport , including an example of a table . I will give it a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM