Mail merge from Java

12,880

Solution 1

Working with MS Word documents is very hard. DOC format is very complicated, DOCX is in theory simpler, but it is rather new and there is no mature, feature rich Java library to work with it and DOC as well.

The easiest solutions to most problems connected with working with MS Office documents is describe in the Joel Spolsky article. I hope you can use this method in your application.

Solution 2

Docx4j has a MailMerger class. It works, but it strips out a lot of formatting in the process.

Solution 3

Have a look at OpenOffice to see [manually] whether it can produce the types of files you need. Just load up some docs, and save some docs and docx versions. If the results pass these simple manual tests, then Docmosis or JODReports can automate this from Java.

Solution 4

If you're open to non-free solutions, Aspose provides what appears to be a very sophisticated Java API for mail merging, among other things.

Share:
12,880
Mike Q
Author by

Mike Q

Updated on June 04, 2022

Comments

  • Mike Q
    Mike Q almost 2 years

    Does anyone have any experience with doing mail merge from Java on a word document? I need to support both doc and docx formats.

    I have heard of Apache POI and docx4j. However, from reading around I'm sure how good the word support is in POI. docx4j only supports docx format as far as I can see.

    Can any suggest either one of the above (and correct my knowledge on support) or another appropriate library. If necessary I would be willing to use one lib for doc and another for docx.

    Thanks.

  • Mike Q
    Mike Q about 14 years
    Thanks, after trying to use the Open Office APIs I'm forced to agree with the article.
  • JasonPlutext
    JasonPlutext about 13 years
    +1 Using LibreOffice to convert doc to docx may work sufficiently well for you. Then in Java you can work exclusively with docx.