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

Free Support Forum - aspose.com

Strange characters for the Merged field with date format

Hi, there is a merged-field with date format inside the word file, after the mail-merge process, it converts to strange character. The field is LQCASE_APPDATE d mmmm yyyy and after mail-merge it shows as following image.png (5.2 KB)

I attached the word file if further investigation is required.
Mina_test2.docx (45.2 KB)

Thank you

@minaeimi,
It seems that you use the wrong MergeField code in your template document. Merge field in your document looks like this:
{ MERGEFIELD LQCASE_APPDATE \@ DATE "d mmmm yyyy" }

To show out without unwanted characters please use one of the following merge field codes:

  • { MERGEFIELD LQCASE_APPDATE \@ "d MMMM yyyy" } to show up as “30 November 2021”
  • { MERGEFIELD LQCASE_APPDATE \@ "d MM yyyy" } to show up as “30 11 2021”

@sergey.lobanov thanks for your reply, I changed the format to ‘d MM yyyy’ and now I see the data as
image.png (4.0 KB)

which is still not desired behaviour.
Do I need to apply any format on the field date before mail-merge?

@minaeimi,
Unfortunately, we were unable to reproduce the same issue on our side. Please check attached ZIP archive (21-11.zip) with template document and output document, produced by following code:

Document doc = new Document(@"C:\Temp\Mina_test2.docx");

String[] fieldNames = new String[] { "LQCASE_APPDATE" };
Object[] fieldValues = new Object[] { DateTime.Today };

doc.MailMerge.Execute(fieldNames, fieldValues);

doc.Save(@"C:\Temp\Mina_test2-merged.docx");

Could you please share your template document? We will investigate the issue and provide you information on it.

I already shared the document in the first post.

@minaeimi,
Could you please share your updated template document with an updated format of a merge field, which causes your data to look like “Tue Nov 02 00:00:00 CET 2021”? We will check if we can reproduce the issue on our side and provide you more information on it.

@sergey.lobanov here is the modified file.
Mina_test2.docx (45.1 KB)

@minaeimi,
It seems that merge field code in your document is wrong(to see the full merge field code in MS Word please right-click on it and choose “Toggle Field Codes”):

{ MERGEFIELD LQCASE_APPDATE \@ DATE "d MM yyyy" } (there is an unnecessary “DATE” word)

To get desired behaviour please change this code to the followng code:

{ MERGEFIELD LQCASE_APPDATE \@ "d MM yyyy" }

@sergey.lobanov regardless of what format I set or any changes in word file, it prints data in this format “Tue Nov 02 00:00:00 CET 2021”, and it is exactly the same format as data in our database.

@minaeimi,
It seems that engine can’t recognize a date in your string, and as a result can’t apply required formatting to it. To get a desired result, you need to remove a 00:00:00 CET substring from your data string:

Document doc = new Document(@"C:\Temp\Mina_test2.docx");

String[] fieldNames = new String[] { "LQCASE_APPDATE" };
String s = "Tue Nov 02 00:00:00 CET 2021";
Object[] fieldValues = new Object[] { s.Remove(12, 12) };

doc.MailMerge.Execute(fieldNames, fieldValues);

doc.Save(@"C:\Temp\Mina_test2-merged.docx");

If all of your data in your database share the same format as a string above, then you can use String.Remove(12, 12) method as a workaround to get a date with desired format in an output document after a mail merge.

@sergey.lobanov thanks, that was the issue. it is solved