我尝试使用C#打开excel工作簿时出现错误 [英] error when i try to open excel workbook with c#

查看:154
本文介绍了我尝试使用C#打开excel工作簿时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI 我尝试使用此代码打开excel工作簿

HI i try to open excel workbook with this code

Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
xlapp.Visible = true;
Microsoft.Office.Interop.Excel.Workbookk xlworkbook = xlapp.Workbooks.Add(0);


并且我从com标签添加了引用,但是当我运行此错误时显示了


旧格式或无效的类型库. (来自HRESULT的异常:0x80028018(TYPE_E_INVDATAREAD))
请帮助我


and i add references from com tab but when i run this error was shown


Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
please help me

推荐答案

尝试以下方法:

使用C#打开和导航Excel [ http://www.dotnetperls.com/excel [
Try these:

Opening and Navigating Excel with C#[^]

http://www.dotnetperls.com/excel[^]

hope it helps :)


可能您遇到了与以下问题相同的问题:http://social.msdn.microsoft.com/Forums/en-CA/Vsexpressvb/thread/4565361b-aeff-4d01-af92-d21a6eb631e3 [ ^ ]
我发现了问题的原因,这是因为用户的本地设置与办公室版本不同,我使用了英语版本,并且在将语言设置为英语后,将国家/地区设置为美国(在区域和语言中)在控制面板下的设置可以正常工作
Probably you have the same problem as described at: http://social.msdn.microsoft.com/Forums/en-CA/Vsexpressvb/thread/4565361b-aeff-4d01-af92-d21a6eb631e3[^]
i found the cause of the problem, it''s because the user local settings are different from the office version, i use the english version and after setting language to english us, and country to united states in the reagional and language settings under control panel it worked fine


听起来像是您可能正在尝试使用旧版本的Visual Studio打开excel一样.可能是您拥有Visual Studio 2008和Microsoft Office2010.请尝试下载版本4框架,并引用2010 interopt dll.

注意:如果使用Microsoft.Office.Interop.Excel.Application的var insteaad,则将有助于提高可读性.
Sounds to me like you may be trying to open excel with a version of Visual Studio that is old. May be that you have Visual Studio 2008 and Microsoft Office 2010. Try to download the Version 4 framework, and reference the 2010 interopt dll.

Note: it would help readability if you used the var insteaad of Microsoft.Office.Interop.Excel.Application.


这篇关于我尝试使用C#打开excel工作簿时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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