views:

25

answers:

2

I am using interop to open Excel files in C#. The current problem I have is that, if the Excel I installed is English, for the opening to work, I have to set LocalSettings to English. It will fail these two do not match.

I found that this is an known issue http://support.microsoft.com/kb/320369. However, I could not always set the thread cultureinfo to English, because I don't have control over what Excel version the user installs. It looks like that the only solution is to find out the languagesettings of the installed Excel, and make sure two the current thread cultureinfo is the same. However, I could not get proper languagesettings from the installed Excel.

Your help is appreciated.

A: 

One option might be to check the version of the installed language pack in the registry. The Technet blog below has more info, see the end of the article for info on the registry keys.

http://blogs.technet.com/b/office_resource_kit/archive/2010/04/02/how-to-determine-which-2007office-system-languages-are-installed.aspx

From the above link:

HKEY_LOCAL_MACHINE\Software\Microsoft\Office\12.0\Common\LanguageResources LanguageResources includes the following registry keys:

  • InstallLanguage Represents the primary editing language.
  • InstalledUIs Provides a list of all available UI Languages on the machine.
  • UILanguage Represents the default display language for the user interface in Office.
  • EnabledLanguages Indicates the locale identifier (LCID) for the language-specific features that are enabled in Office.

The Windows operating system uses LCIDs to identify languages in the Windows registry. For a list of language identifiers, see Language identifiers in the 2007 Office system (http://technet.microsoft.com/en-us/library/cc179219.aspx).

Chris Taylor
+1  A: 

Can't answer your question directly, but I've recently moved to NPOI for all my C# Excel programming.

It's a really good library, and doesn't require Excel to be installed on the servers, and produces native I got up to speed in less than a day.

It only works with Excel 2003 files, and the documentation is not excellent. However, it comes with a full set of examples which show many expected use cases.

Given the nature of your problem, and NPOI's zero requirement for an Excel installation, NPOI may not care about the EnglishSettings.

Paul Alan Taylor
+1, If this is an option for the OP, I agree NPOI is the way to go.
Chris Taylor