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

Free Support Forum - aspose.com

Localization support when mail merging

Does Aspose Words have support for mail merging numerical values that are provided with a European style decimal point (i.e. a comma)? I have seen previous posts about this from a few years ago that indicate this is not possible, however, I was wondering if things have changed since then? I have attempted to make a small test to demonstrate the issue:

Dim newDoc As New Document("tmp1.doc")
Dim fieldNames(0) As String
fieldNames(0) = "assmdocfld6530tmp"
Dim fieldValues(0) As String
fieldValues(0) = "16,9329"
newDoc.MailMerge.Execute(fieldNames, fieldValues)

My machines locale is set to nl-be, tmp1.doc has its language set to “Dutch (Belgium)” and contains the following mergefield:

{ MERGEFIELD assmdocfld6530tmp \#0,00 }

The result of the merge is 017 (not the expected value of 16,93). However, if I change the language to English, the machines local to en-us, the field formatting to #0.00 and the value to 16.9329 then the result of the mail merge is correct.

Is it possible to use non en-us codes in a mergefield or does aspose require the use of en-us?



Thanks for your inquiry. Aspose.Words requires picture format switches in merge fields to be in the US (Invariant Culture) format. So, please try using the following switch.
{ MERGEFIELD test \# #,##0.00 }
Here is code I used for testing:

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
// Set German culture for testing. Number format in Germany is 123.456.789,00 
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
Document doc = new Document(@"Test001\in.doc");
doc.MailMerge.Execute(new string[] { "fieldName1" }, new object[] { 0 });
Thread.CurrentThread.CurrentCulture = currentCulture;

In the output document you will see the expected value 0,00.
Hope this helps.
Best regards.

Thanks for the response. We currently have hundreds (if not thousands) of documents with non US format switches (they are all Dutch); is there any advice/recommendations you could give to automating a conversion into US formatting in order to continue their correct functioning with Aspose Words?

Hi David,
Thanks for this additional information. Yes this sounds understandable, you can automatically convert these switches into the US Invariant Culture using Aspose.Words.
Please see this thread here of an example implementation of how to search through all fields in a document, retrieve the field code, then use regular expressions to find and replace a part of text, and finnally enter in the new field code.
If you have any trouble getting this to work we are happy to assist.