的Microsoft.Office.Interop.Excel不会对64位工作 [英] Microsoft.Office.Interop.Excel doesn't work on 64 bit

查看:290
本文介绍了的Microsoft.Office.Interop.Excel不会对64位工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MS的Visual Web Developer 2008防爆preSS埃德开发时,我遇到了一个问题。
ASP.NET开发C#在Windows7的64位操作系统。

我试图打开一个Excel文档,但它给了我旧格式或无效的类型库。 (从HRESULT异常:0x80028018(TYPE_E_INVDATAREAD))

我没有配置构建于所有处理器(任何CPU,64,86),但它不工作。我在互联网上搜索答案,但无法找到如何处理它。

奇怪的是相同的code工作在同一个系统上,当我在微软的Visual C#2010前preSS发达!怎么来的?是不是同一个DLL工作背后?

我是否需要更改COM DLL因此这将x64系统上工作?

请帮帮我,我该怎么办?

我的code是:

 使用Excel =的Microsoft.Office.Interop.Excel;
xlApp =新Excel.Application();
__Log(期初+ excelFileName);
xlWorkBook = xlApp.Workbooks.Open(excelFileName,0,真实,5,,,真实,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,\\ t的,假的,假的,0,真的,1 ,0);
xlWorkSheet =(Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);


解决方案

挖我发现有微软互操作与COM对象错误(至少我的情况是MS Excel 2010中)后上网。

该错误是.NET会检查你的线程(C#或VB code)定位是适合你之前安装MS Excel的定位,如果没有它告诉了 Microsoft.Office。互操作库是旧的或无效的。

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

这时有两种选择来解决这个问题:


  1. 要改变你的线程本地化(由code)

  2. 安装语言包为您的Office

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

 使用的System.Threading; //用于设置线程的本地化,以适应
使用System.Globalization; //将MS Excel应用程序本地化,因为MS的bugThread.CurrentThread.CurrentCulture =新的CultureInfo(EN-US);
excelFileName = System.IO.Path.Combine(excelPath,Ziperty购买模型的Web 11_11_2011.xlsm);

希望它帮助:)
GR8日

I've encountered a problem when developing on MS Visual Web Developer 2008 Express Ed. Developing ASP.NET C# on Windows7 64 bit OS.

I'm trying to open an Excel document, but it gives me Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))

I did configured the build to all processors (Any CPU, x64, x86) but it doesn't work. I searched the answer on the internet but couldn't find out how to handle it.

The weird thing is the same code worked on the same system when I developed on Microsoft Visual C# 2010 Express! how come? isn't it the same dll working behind?

Do I need to change that COM dll so it'll work on x64 system?

Please help me, what can I do?

My code is:

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

解决方案

After digging the internet I found out that there is a bug in Microsoft Interop with COM objects (at least with my case which is MS Excel 2010).

The bug is that .NET checks that your thread (C# or VB code) localization is suitable to MS Excel localization you installed earlier, and if not it tells that the Microsoft.Office.Interop library is old or invalid.

Your thread localization is derived from your computer regional settings (from the control panel --> regional and language)

Then there are two options to solve this problem:

  1. To change your thread localization (by code)
  2. Install language pack for your Office

The first solution goes like this:

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");

Hope it helps :) gr8 day

这篇关于的Microsoft.Office.Interop.Excel不会对64位工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆