Is there a Java API that can create rich Word documents?

billjamesdev picture billjamesdev · Oct 15, 2008 · Viewed 152.1k times · Source

I have a new app I'll be working on where I have to generate a Word document that contains tables, graphs, a table of contents and text. What's a good API to use for this? How sure are you that it supports graphs, ToCs, and tables? What are some hidden gotcha's in using them?

Some clarifications:

  • I can't output a PDF, they want a Word doc.
  • They're using MS Word 2003 (or 2007), not OpenOffice
  • Application is running on *nix app-server

It'd be nice if I could start with a template doc and just fill in some spaces with tables, graphs, etc.

Edit: Several good answers below, each with their own faults as far as my current situation. Hard to pick a "final answer" from them. Think I'll leave it open, and hope for better solutions to be created.

Edit: The OpenOffice UNO project does seem to be closest to what I asked for. While POI is certainly more mainstream, it's too immature for what I want.

Answer

Rob Garverick picture Rob Garverick · Nov 2, 2008

In 2007 my project successfully used OpenOffice.org's Universal Network Objects (UNO) interface to programmatically generate MS-Word compatible documents (*.doc), as well as corresponding PDF documents, from a Java Web application (a Struts/JSP framework).

OpenOffice UNO also lets you build MS-Office-compatible charts, spreadsheets, presentations, etc. We were able to dynamically build sophisticated Word documents, including charts and tables.

We simplified the process by using template MS-Word documents with bookmark inserts into which the software inserted content, however, you can build documents completely from scratch. The goal was to have the software generate report documents that could be shared and further tweaked by end-users before converting them to PDF for final delivery and archival.

You can optionally produce documents in OpenOffice formats if you want users to use OpenOffice instead of MS-Office. In our case the users want to use MS-Office tools.

UNO is included within the OpenOffice suite. We simply linked our Java app to UNO-related libraries within the suite. An OpenOffice Software Development Kit (SDK) is available containing example applications and the UNO Developer's Guide.

I have not investigated whether the latest OpenOffice UNO can generate MS-Office 2007 Open XML document formats.

The important things about OpenOffice UNO are:

  1. It is freeware
  2. It supports multiple languages (e.g. Visual Basic, Java, C++, and others).
  3. It is platform-independent (Windows, Linux, Unix, etc.).

Here are some useful web sites: