We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words for Java - MailMerge

When testing the Dinner Invitation example I found out that if the same MailMerge field (in the example “ContactName”) appears twice on the page, only the first instance is “merged” with database data.

Is this a known issue?

Kind Regards,



Thanks for your inquiry. If you use simple mail merge (execute method) then all fields with same names will be filled with data. You can test this using the following simple code:

//Open new document

Document doc = new Document("C:\\Temp\\in.doc");

//Execute mail merge

doc.getMailMerge().execute(new String[] { "test" }, new Object[] { "value of field" });

//Save output doc


You should put two merge fields named “test” in the document. See the following link to learn how to prepare document.


But if you execute mail merge with regions (executeWithRegions method) only fields inside region will be filled.

Best regards.

Thanks for Your reply.

In my case, it did not answer my question.

The failing (in my opinion) test case is the Dinner Invitation example which is part of the

Aspose.Words for Java Demo.

I did not modify the template document with MailMerge fields, but I did found out that

the line starting with "Dear <> " still had that content (was not merged).

Please see the attachment

I did save the document as ooxml (.docx). I will test with .doc to verify that the behaves the same.

Kind Regards,


The same thing with .doc files.

The problem seems to be related to the way ResultSet’s are handled.

If I use a MergeField several times in the template document, I have to populate it as for one record only -> doc.getMailMerge().execute(new String[] {“MyName”, “MyAddress”}, new String[] {“Tony Homer”, "Home Town})

Kind Regards,


Hi Tapani,

Thanks for your report. You right, the ResultSet improperly handled in the demo: we have used non-scrollable cursor so the ResultSet can’t get the same field twice. Thanks to you we fixed this bug in the demo.

For workaround you can change one line in Demo.createStatement() form:

return connection.createStatement();


return connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

By the way, few releases ago the demos worked well – I remember I checked these docs by my own eyes. Probably the cursor was broken during some improvementJ

Best Regards,


Now it works as expected!

Kind Regards,