How to change the FlexCel locale.
Some formats in Excel change depending on the locale of your machine. We have discussed those formats more in depth in the tip about internal numeric formats.
When FlexCel renders a file to pdf or other format, it needs to know how you want those locales printed. Is it dd/mm/yyyy or mm/dd/yyyy? As you would expect, if you don't do anything, FlexCel picks the locale from your machine settings. If you want to change how FlexCel renders those locale-dependent formats, the simplest way is to just change the machine settings. But sometimes you can't or don't want to change the machine locale, but still want FlexCel to render those formats as if the machine had some specific locale.
In .NET it is simple to change the locale, you can just change the thread locale by changing CurrentCulture and CurrentUICulture
You might change them at the start of your application (or when creating new threads), or you might change it before working with FlexCel and set them back after the FlexCel work is done, as in the example below. You might even have different threads working in different locales.
Example:
CultureInfo SaveLocale = System.Threading.Thread.CurrentThread.CurrentCulture;
CultureInfo SaveUILocale = System.Threading.Thread.CurrentThread.CurrentUICulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");
try
{
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
try
{
XlsFile xls = new XlsFile("chinese.xlsx", true);
using (FlexCelPdfExport pdf = new FlexCelPdfExport(xls, true))
{
pdf.Export("chinese.pdf");
}
}
finally
{
System.Threading.Thread.CurrentThread.CurrentUICulture = SaveUILocale;
}
}
finally
{
System.Threading.Thread.CurrentThread.CurrentCulture = SaveLocale;
}