Free Support Forum - aspose.com

Mergefield format for number (field code)

Hi Aspose.Team,

I'm a total newbie to culture in code, trying ot figure out how it is in Aspose.Words.
Thanks for your help.

In my words document, I'm setting format for mergefield as:

{MERGEFIELD number \# #,00 }

Having in mind that this will run under french culture ( ex: 10 ->10,00=10.00).

How does Aspose.Words react with this field code?
Do I need to set regional setting correctly on my machine, for Aspose.Words to understand the field code as french culture?

Also, I have to toggle between english and frend culture for my user.
How can I achieve this in Aspose.Words? Do I need two document with two different field code?

Hi

Thanks for your inquiry. You can try to set culture for the current thread. See the following code.

Document doc = new Document(@"317_100672_nicson\in.doc");

//Unated States

string UserLocale = "en-US";

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(UserLocale);

string[] names = { "Field1" };

object[] values = { 100000.00 };

doc.MailMerge.Execute(names, values);

//French

UserLocale = "fr-FR";

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(UserLocale);

names[0] = "Field2";

doc.MailMerge.Execute(names, values);

//Denmark

UserLocale = "da-DK";

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(UserLocale);

names[0] = "Field3";

doc.MailMerge.Execute(names, values);

doc.Save(@"317_100672_nicson\out.doc");

I used very simple template like the following.

{ MERGEFIELD Field1 \# "#,##0.00" }

{ MERGEFIELD Field2 \# "#,##0.00" }

{ MERGEFIELD Field3 \# "#,##0.00" }

I hope that this will help you.

Also I think that you can find more information here.
http://www.aspose.com/Community/Forums/thread/50436.aspx

Best regards.

Thank you very much.
Your answer puts total light on the subject.
It works perfectly now.