silent tone
silent tone

Reputation: 549

Specify region & culture for Microsoft Office interop

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.

Upvotes: 0

Views: 3206

Answers (3)

Hans van Dodewaard
Hans van Dodewaard

Reputation: 713

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;

Upvotes: 1

Tony Kh
Tony Kh

Reputation: 1572

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.

Upvotes: 1

Marek Kwiendacz
Marek Kwiendacz

Reputation: 9864

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.

Upvotes: 0

Related Questions