8

我在 MS Visual Web Developer 2008 Express Ed 上开发时遇到了问题。在 Windows7 64 位操作系统上开发 ASP.NET C#。

我正在尝试打开一个 Excel 文档,但它给了我Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))

我确实为所有处理器(任何 CPU、x64、x86)配置了构建,但它不起作用。我在互联网上搜索了答案,但找不到如何处理它。

奇怪的是,当我在 Microsoft Visual C# 2010 Express 上开发时,相同的代码在同一系统上运行!怎么会?后面工作的不是同一个dll吗?

我是否需要更改该 COM dll 才能在 x64 系统上运行?

请帮帮我,我该怎么办?

我的代码是:

using Excel = Microsoft.Office.Interop.Excel;
xlApp = new Excel.Application();
__Log("Openning " + excelFileName);
xlWorkBook = xlApp.Workbooks.Open(excelFileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
4

1 回答 1

20

在挖掘互联网后,我发现 Microsoft Interop 与 COM 对象存在一个错误(至少在我的情况下是 MS Excel 2010)。

错误是 .NET 检查您的线程(C# 或 VB 代码)本地化是否适合您之前安装的 MS Excel 本地化,如果不适合,则表明该Microsoft.Office.Interop库已旧或无效。

您的线程本地化来自您的计算机区域设置(来自控制面板 --> 区域和语言)

那么有两种方法可以解决这个问题:

  1. 更改您的线程本地化(通过代码)
  2. 为您的 Office 安装语言包

第一个解决方案是这样的:

using System.Threading;     // For setting the Localization of the thread to fit
using System.Globalization; // the of the MS Excel localization, because of the MS bug

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
excelFileName = System.IO.Path.Combine(excelPath, "Ziperty Buy Model for Web 11_11_2011.xlsm");

希望它有所帮助:) gr8 day

于 2011-11-25T22:49:10.493 回答