I'd like to access Excel through .net interop. I need to use a different region, but don't want to change the region for the whole OS. Is there any way to specify this programmatically? 开发者_运维技巧The LanguageSettings property of the ApplicationClass is read-only.
You may set the current thread's culture :
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
Furthermore, there is/was a bug in Excel when it was necessary to specify en-US culture to use Interop. It depends on excel configuration (whether updates were applied or not)
Your OS culture may be, for an instance, Russian, but if you explicitly set thread's culture to en-US all will be allright.
If it's about the separators, you can do it this way:
var ci = new CultureInfo(locale);
var excelApp = new Microsoft.Office.Interop.Exce.Application();
excelApp.UseSystemSeparators = false;
excelApp.DecimalSeparator = ci.NumberFormat.NumberDecimalSeparator;
excelApp.ThousandsSeparator = ci.NumberFormat.NumberGroupSeparator;
It could be ddangerous to your application. In my program when OS language version was different than Office language version then program crashed because Office tried to run automatically language pack. Strange behaviour.
精彩评论