Cultureinfo 不匹配导致 Excel 自动化失败

发布于 2024-09-25 21:29:31 字数 374 浏览 4 评论 0原文

我正在使用互操作性在 C# 中打开 Excel 文件。我目前遇到的问题是,如果我安装的Excel是英文的,为了打开工作,我必须将LocalSettings设置为英文。这两个不匹配将会失败。

我发现这是一个已知问题http://support.microsoft.com/kb/320369 。但是,我无法始终将线程cultureinfo设置为英语,因为我无法控制用户安装的Excel版本。看起来唯一的解决方案是找出已安装的Excel的语言设置,并确保两个当前线程的cultureinfo相同。但是,我无法从已安装的 Excel 中获取正确的语言设置。

感谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

桜花祭 2024-10-02 21:29:31

无法直接回答您的问题,但我最近已转向 NPOI 进行所有 C# Excel 编程。

这是一个非常好的库,不需要在服务器上安装 Excel,并且可以生成原生的库,我在不到一天的时间内就掌握了速度。

它仅适用于 Excel 2003 文件,并且文档并不出色。但是,它附带了一整套示例,显示了许多预期的用例。

鉴于您的问题的性质,以及 NPOI 对 Excel 安装的零要求,NPOI 可能不关心 EnglishSettings。

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.

鸵鸟症 2024-10-02 21:29:31

检查注册表的另一个选项是使用以下命令从 Excel 应用程序检索语言:

New System.Globalization.CultureInfo(
ExcelApp.LanguageSettings.LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI))

这需要引用 Office.dll v14.0

Another option over checking the registry is retrieving the language from the excel app using the following:

New System.Globalization.CultureInfo(
ExcelApp.LanguageSettings.LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI))

This requires a reference to Office.dll v14.0

如梦 2024-10-02 21:29:31

一种选择可能是检查注册表中已安装语言包的版本。下面的 Technet 博客提供了更多信息,有关注册表项的信息请参阅文章末尾。

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

从上面的链接:

HKEY_LOCAL_MACHINE\Software\Microsoft\Office\12.0\Common\LanguageResources
LanguageResources 包括以下注册表项:

  • InstallLanguage 表示主要编辑语言。
  • InstalledUIs 提供计算机上所有可用 UI 语言的列表。
  • UILanguage 表示 Office 中用户界面的默认显示语言。
  • EnabledLanguages 指示 Office 中启用的特定于语言的功能的区域设置标识符 (LCID)。

Windows 操作系统使用 LCID 来识别 Windows 注册表中的语言。有关语言标识符的列表,请参阅 2007 Office system 中的语言标识符 (http://technet.microsoft.com/en-us/library/cc179219.aspx)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文