tags:

views:

445

answers:

7

How can you edit a word document with Java?

+4  A: 

Take a look at http://poi.apache.org/

Bryan Denny
+1 for a worthwhile project, but according to their page, the Word aspect is a bit of an afterthought; POI looks like it's focused on Excel. It can't handle .docx, and it seems they're looking for a project lead on the Word side. Don't know if that matters to the poster.
BlairHippo
+2  A: 

I'm not familiar with anything standard. It also depends on the version of Word, since various versions use different file formats.

The POI project from Apache is supposed to provide ways to do this:

Uri
A: 

You could also try something like SIKULI.

prometheus
+3  A: 

You can use COM to do that also. Use a Java COM interop library like JACOB (JAVA COM BRIDGE): http://sourceforge.net/projects/jacob-project/

Here is a tutorial using Jacob to talk to MS Word: http://www.land-of-kain.de/docs/jacob/

The other library that looks promising and that will solve the cross-platform problem is J-Interop: http://www.j-interop.org/.

Hannes de Jager
+1 for Jacob, which has been a lifesaver for me in the past. But do note that this will lock you into Windows; you wouldn't be able to run a Jacob-based solution on a Unix or Mac box. No idea if that's a problem for the poster, though.
BlairHippo
For the cross-platform issue: see my edit on J-Interop above
Hannes de Jager
+3  A: 

In the past, I've solved problems like this using OpenOffice.org's Java API. It's not exactly lightweight, but the licensing terms are generous and it has the backing of a development community with a vested interest in making sure it can parse whatever weirdness Microsoft inflicts on the Word file format. Might be worth a look.

BlairHippo
A: 

You could try Docmosis, which allows you to populate or produce word docs from Java. It's based on BlairHippo's suggestion of using the OpenOffice API but without needing to learn the api. JODReports is similar.

jowierun
A: 

docx4j (apache license)

plutext
There is also docx4all, a Swing-based wordprocessor for docx documents.
plutext