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

# How to get date localisation during mailmerge

We are producing legal documents based on Word templates written and formatted in Italian.

The date fields use the dd-MMM-yy format.

If we run a regular Word mailmerge (i.e. on the desktop), we see the dates formatted using Italian months e.g. 21st May would appear as 21-Mag-07.

The text is of course formatted as being Italian (for spell checking purposes) and I think this must be where Word is getting its localisation cue.

If we take the same mailmerge template and run it through ASPOSE, then the same date fields are formatted in English, e.g. 21-May-07.

I double checked the template and the text is still formatted as Italian, so I’m assuming that ASPOSE does not follow this setting when formatting dates.

It looks like we would have to workaround this by formatting localisation in our data, but since it is likely we will produce documentation for other European languages in future, it would be much more preferable that the document formatting drives this, so French templates would create French dates, German produce German, etc.

Hope this makes sense, and hope there is a solution!

Mark Hirst, ICS Solutions

Hi

Thanks for your request. Aspose.Words uses standard .NET functions to format values. The output will be different of course depending on the current culture on the machine. So you can set culture. See the following code:

CultureInfo tempCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
string[] names = { "date" };
object[] values = { DateTime.Now };
Document doc = new Document(@"Test193\in.doc");
doc.MailMerge.Execute(names, values);
doc.Save(@"Test193\out.doc");


http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.getconsolefallbackuiculture.aspx

Hope this helps.

Best regards.

Thanks,

We are localising the web interface already using ASP.NET localisation support and the CurrentCulture is part of that.

The culture of the user or current process is not neccessarily the language of the documents that the system will be producing. At the moment, our users will see UK English or Italian in the user interface, but the document output is in Italian. Typically, our users will be English, but will be producing Italian documentation.

Whilst we could simply fix the data as being Italian or use the current users localisation settings as a guide, the localisation of dates really is driven by the language of the Word template, since this is worded in Italian, and potentially in other European languages in future.

Ideally, the language settings of the document would drive it, which is how a desktop mailmerge in Word works.

Mark

Hi

Thanks for your request. You can try using LocaleID. For example see the following code:

//Save current culture
//Open document
Document doc = new Document(@"Test193\in.doc");
//Get localeID
int localeID = doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Style.Font.LocaleId;
switch (localeID)
{
case 1040: //This is italian locale ID
break;
case 2057: //English - United Kingdom
break;
//etc...
}

string[] names = { "date" };
object[] values = { DateTime.Now };
doc.MailMerge.Execute(names, values);
doc.Save(@"Test193\out.doc");


Best regards.

Alexey,

Thank you for responding so quickly!!

Mark

Hi Alexy, I’ve done exactly the same thing as you have above on my document (that I’ve attached), but it doesn’t seem to work.

It looks to me like doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Style.Font.LocaleId

is set to 1033 or en-us… even if the document language has been changed to French Canadian? Any thoughts?

Thanks,

Jules

My Bad… i didn’t set the document language correctly in the word doc.

thanks.

Hi

It is nice that you already found solution independently.

Best regards.