14

How can you edit a word document with Java?

0

6 Answers 6

5

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

Sign up to request clarification or add additional context in comments.

3 Comments

+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.
I tried poi and while it can handle simple text docs, if there are images in your original template, poi will lose them.
docx4j (which I work on) is focused on docx, then pptx, then xlsx in that order. These days POI does support the XML file formats.
4

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/.

1 Comment

+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.
3

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.

Comments

2

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:

Comments

0

You could also try something like SIKULI.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.