Insert Text from a File INCLUDETEXT Field during Executing Mail Merge on Word Template Document with Aspose Words for Java Code

Hi Aspose,
We can see a change in behaviour in the latest version of Aspose Words when performing a mailmerge that does not seem right. When an INCLUDETEXT field is used to include another document that sets a value to be used in the original document, the value is not included in the result. This was working as expected in Aspose 20.11 and earlier but has changed in Aspose 20.12 onwards.

Attached is a minimal test case. To run, replace the licence file and run with IntelliJ.

The expected result is that the output document mailmerge-result.docx should contain the text “Manager The RED pension scheme Ltd Redhill” because that is the value of the REF SigBlock defined by the included document. A copy of the expected result (generated with the same code and Aspose Words 20.11) and the actual result with Aspose 21.1 are included in the example.

Included in the code are some commented-out lines that represent things we currently do in our real application to give some context, specifically we use the option setUnconditionalMergeFieldsAndRegions and we also update IF fields before unlinking them. However neither of these changes makes a difference in this case.

I can’t see a clear workaround for this issue. If I update all fields before unlinking, then the text is included, but it is duplicated which is incorrect. If I change the data source so that there are no records (i.e. change MyDataSource so that moveNext always returns false) then the result is as expected, but this is not possible in a real application because the data source will always contain records.

Please can you advise if this is a bug that should be fixed, or if there is some other way we can get our examples like this to work as expected?

Many thanks in advance,
Ned Smith (118.4 KB)


We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-21790. We will further look into the details of this problem and will keep you updated here on the status of the linked issue. We apologize for your inconvenience.

This has been raised under paid support

Containerize.IdentityServer - Single sign-on to access all applications and services of Aspose Pty Ltd.


If everything goes by plan, then we are very hopeful to include the fix of this issue in next 21.3 March release of Aspose.Words for Java. You will be notified here as soon as a version containing the fix of this issue will get published.

The issues you have found earlier (filed as WORDSNET-21790) have been fixed in this Aspose.Words for .NET 21.3 update and this Aspose.Words for Java 21.3 update.