I am using aspose-words-22.12 version.
\@ MM/dd/yyyy
format is not working while localization is use.
Local is UK and date format is dd/MM/yyyy and I would like to convert in MM/dd/yyyy format then it will not work as expected.
Example :
date_c : 03/04/2017 (dd/MM/yyyy - 03 April 2017)
while applying \@ MM/dd/yyyy
in word document its print as a 03/04/2017
Following is my code
MailMerge merge = doc.getMailMerge() ;
DataSet dataSet = new DataSet() ;
dataSet.readXml( xmlFilepath ) ;
merge.executeWithRegions(dataSet);
doc.save("E:\\\\sample letter with dates\\\\sample letter with dates2.docx") ;
@akondewar Unfortunately, I cannot reproduce the problem. I have used the following simple code for testing:
Locale current = CurrentThreadSettings.getLocale();
CurrentThreadSettings.setLocale(Locale.UK);
// Create a simple template with merge fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Date format 'MM/dd/yyyy': ");
builder.insertField("MERGEFIELD date \\@ MM/dd/yyyy");
builder.writeln();
builder.write("Date format 'dd/MM/yyyy': ");
builder.insertField("MERGEFIELD date \\@ dd/MM/yyyy");
// Execute mail merge.
Date date = new GregorianCalendar(2017, 4 - 1, 3).getTime();
doc.getMailMerge().execute(new String[] { "date" }, new Object[] { date });
doc.save("C:\\Temp\\out.docx");
CurrentThreadSettings.setLocale(current);
Both date formats works fine on my side. The output is the following:
Date format 'MM/dd/yyyy': 04/03/2017
Date format 'dd/MM/yyyy': 03/04/2017
Hi,
Thanks for valuable reply. But we are using com.aspose.words 15.11.0.0 jar.
There may be regression impact if I update the JAR, so it cannot be done at this time.
We are giving date format in the word document.
We need solution for this version.
Mixed date format is used while using German Locale.
date format is '\@ MM.dd.yyyy'
it’s generate 09.01.2021 , 12/24/2022 , 24/11/2022 etc.
@akondewar Could you please attach your sample input, output and expected output documents along with code that will allow us to reproduce the problem? We will check the issue and provide you more information.
Please note, we do not provide fixes for old versions of Aspose.Words, all fixes and improvements are delivered with new versions of Aspose.Words. 15.11 version of quite old, it has been released about 7 years ago, so I would advice you to update to the newer version.
@alexey.noskov Hi,
We have implemented above given solution and issue has been solved for date format issue.
Now getting regression impact of this code.
Issue : for example \# "#,###.000
format is not applied while Locale set as 'nl_NL'
(Dutch) or 'en_ZA'
Input value is ‘2.000000’
Output value : 2000000,000 for ‘nl_NL’
Input value : 500.000000
Output Value : 500000000, 00
Input value is ‘2.000000’
Output value : 2, .000 for ‘en_ZA’ (Space beetwwen 2, and .000)
It is working fine for ‘en_US’ .
If I commented CurrentThreadSettings.setLocale
then working fine.
Attached code and input and out files has been attached.
ToForum.zip (262.4 KB)
@akondewar Culture also affects how values from XML are interpreted. In case of English culture, the value 2.000000
is interpreted as double value of 2
. But with Dutch culture it is interpreted as double value of 2000000
since dot is used as a thousand separator not as a decimal point. That is why the problem occurs. You should make sure the same data is used for executing mail merge.
Hi Alexy
Thanks for valuable input.
With aspose 15.11, formating was working fine, however, facing issue after upgrading the aspose jar and implementing CurrentThreadSettings.setLocale.
Kindly guide us how to deal with Culture for multi localization. If you have any code snippet please share with us.
Not org local, user swedish_number_format_wrong.pdf.pdf (24.0 KB)
@akondewar Probably in your case you should use invariant culture in your code, but specify the required culture in the template for date mergefields. Then you can use FieldOptions.FieldUpdateCultureSource
property and FieldUpdateCultureSource.FIELD_CODE
to instruct Aspose.Words to use culture specified in the template to format date values in your template.