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

Free Support Forum - aspose.com

Aspose Striping spaces from around MailMerge Fields

Dear Sir/Madam,

We use Aspose.Word for Java to generate letters in our program.
Letter Templates have “merged fields” that are populated with values from Database.

Some time ago we upgraded from “Aspose.Words.jdk16.jar” to “aspose-words-18.2-jdk16.jar”
and encountered an issue when Aspose cuts the whitespaces at the end and the beginning of the merged fields, however they are crucial for our logic.
For example : now there is no space between Salutation and Name - “Ms.Patricia”

I found out that this is a bug in Aspose 18.2 version
(Is Aspose Striping spaces from around MailMerge Fields)

I wonder if this bug has already been fixed?
Please, advise.

@zambergv Aspose.Words cutting whitespaces is not an error, actually is the expected behavior since MS Word app cut that whitespaces as well, and Aspose.Words API try to mimic the MS Word behavior.
Also, in the post that you referenced an user found a workaround to prevent strip whitespaces

Thank you Eduardo.
I am just no clear with that workaround…
Should I just create that class “public class FormatMergeFields” inside my project and it supposed to fix my issue?

@zambergv the name of the class is up to you, but it should implement the Aspose Interface IFieldMergingCallback (see an example here). If you add a reference to that class in the document, the Aspose API will use it during the merge process, allowing you to extend those methods and provide the expected behavior, in this case prevent trimming the leading an tailing whitespaces.

Thank you Eduardo. I will give it a try…

Thanks a lot Eduado. It worked.

1 Like