在C#上打开Excel工作表时出现错误 [英] Getting a error when Opening excel sheet on C#

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

问题描述

嗨.....

我正在使用MS Office 2003和Visual Studio 2008.我已经添加了对Microsoft.Office.Interop.Excel 11.0库的引用.

添加了以下代码:

private void button1_Click(object sender, EventArgs e)
        {
            object format = 5;//Nothing value.

            ApplicationClass xlApp = new ApplicationClass();
            Workbook xlBook = xlApp.Workbooks.Open("D:\\WORKS\\M2ACS\\bin\\Debug", 0, false, format, null, null, false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, null, true, false, 0, true, false, false);
            Sheets xlSheets = xlBook.Worksheets;
            Worksheet xlSheet = (Worksheet)xlSheets.get_Item("Sheet1"); // open Sheet1.
            xlApp.Visible = true;
        }





得到错误:

无法将类型为"Microsoft.Office.Interop.Excel.ApplicationClass"的COM对象转换为接口类型为"Microsoft.Office.Interop.Excel._Application".此操作失败,因为对IID为"{000208D5-0000-0000-C000-000000000046}"的接口的COM组件上的QueryInterface调用由于以下错误而失败:加载类型库/DLL出错. (来自HRESULT的异常:0x80029C4A(TYPE_E_CANTLOADLIBRARY)).



请帮助我解决此错误

解决方案

嗨...........

我不认为代码中有pblm,bcz .​​.在其他系统中也可以.我认为安装ms office时缺少一些dll.在此基础上我需要帮助

thanku


看看这个:
MSDN:如何:使用COM Interop创建Excel电子表格 [ ^ ]

Hi.....

I am using MS office 2003 and Visual studio 2008 .I have added a reference to Microsoft.Office.Interop.Excel 11.0 library .

Added the following code:

private void button1_Click(object sender, EventArgs e)
        {
            object format = 5;//Nothing value.

            ApplicationClass xlApp = new ApplicationClass();
            Workbook xlBook = xlApp.Workbooks.Open("D:\\WORKS\\M2ACS\\bin\\Debug", 0, false, format, null, null, false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, null, true, false, 0, true, false, false);
            Sheets xlSheets = xlBook.Worksheets;
            Worksheet xlSheet = (Worksheet)xlSheets.get_Item("Sheet1"); // open Sheet1.
            xlApp.Visible = true;
        }





Getting the error:

Unable to cast COM object of type ''Microsoft.Office.Interop.Excel.ApplicationClass'' to interface type ''Microsoft.Office.Interop.Excel._Application''. This operation failed because the QueryInterface call on the COM component for the interface with IID ''{000208D5-0000-0000-C000-000000000046}'' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).



Plz.. help me to solve this error

解决方案

Hi..........

I dont think there is a pblm in the code, bcz.. it is work in other systems. i think some dll are missing while installation of ms office.I need a help on this basis

thanku


Have a look at this:
MSDN: How to: Use COM Interop to Create an Excel Spreadsheet [^]


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

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