Issue with German decimal formatting - Xml to pdf using word template

Hi,
last year we upgraded Aspose.words from 18.7 to 23.3.
Now we found that with a German locale numbers are not printed right using a numeric format read by a template docx.
For example, a double 3480.0 with format “#.##0,00” is printed as 34.800.0 with aspose 23.3, while in 18.7 it was correctly printed as 3.480,00.

Here a sample project where I’ve reproduced the error:
AsposeTest.zip (41.7 KB)
There you can find the two printed pdfs and the docx template.

I think that the problem is that the double is converted as String in the xml. But why in 18.7 it worked fine?
Another problem is that our software is used in different countries and maybe we should implement a logic that works with different locale and formats.

Thank you.

@KSTS As I can see you are using IMailMergeDataSource to get data from XML. Why do not you use DataSet? I have tested your template with the following XML:

<Data>
	<Amount>
		<value>3480.0</value>
		<currency>EUR</currency>
	</Amount>
</Data>

And the following simple code:

Locale current = CurrentThreadSettings.getLocale();
CurrentThreadSettings.setLocale(Locale.GERMANY);
        
DataSet ds = new DataSet();
ds.readXml("C:\\Temp\\data.xml");
    
Document doc = new Document("C:\\Temp\\in.docx");
doc.getMailMerge().setUseNonMergeFields(true);
doc.getMailMerge().executeWithRegions(ds);
doc.save("C:\\Temp\\out.pdf");
    
// Restore locale.
CurrentThreadSettings.setLocale(current);

The output is correct in this case: out.pdf (11.9 KB)

With your code you can try parsing the double value from XML to get the correct result. With the above XML, you can modify getValue method in XmlMailMergeDataTable like this:

fieldValue.set(fieldName.equals("value") ? Double.parseDouble(value.getTextContent()) : value.getTextContent());
1 Like