为什么我应该得到这个错误?名称'Excellibrary'在当前上下文中不存在 [英] Why I Should Get This Error?The Name 'Excellibrary' Does Not Exist In The Current Context

查看:86
本文介绍了为什么我应该得到这个错误?名称'Excellibrary'在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何解决这个错误???



Aaqib

解决方案

我想你是得到这个错误来创建一个excel文件



尝试创建excel就像



 使用 Excel = Microsoft.Office.Interop.Excel; 
使用 System.Reflection





public void CreateExcel(string fileName)

{

对象缺失= Missing.Value;

Microsoft.Office.Interop.Excel.Application m_objExcel = new Microsoft.Office。 Interop.Excel.Application();

Microsoft.Office.Interop.Excel.Workbooks m_objWorkBooks = m_objExcel.Workbooks;

Microsoft.Office.Interop.Excel.Workbook m_objWorkBook = m_objWorkBooks.Add(true);

Microsoft.Office.Interop.Excel.Sheets m_objWorkSheets = m_objWorkBook.Sheets; ;

Microsoft.Office.Interop.Excel.Worksheet m_objWorkSheet =(Microsoft.Office.Interop.Excel.Worksheet)m_objWorkSheets [1];

m_objWorkBook.SaveAs(fileName,missing,missing,missing,missing,missing,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,

缺少,遗失,丢失,失踪,失踪);

m_objWorkBook.Close(假,缺失,遗失);

m_objExcel.Quit();

}


您可能1)没有安装Excel; 2)它已安装,但您没有参考互操作组件; 3)您引用了它,但是您应该使用正确的(完全限定的,完整的)类型名称或使用使用指令来解析其全名,并使用名称空间。



我宁愿建议使用Open XML SDL,那么你就不需要安装Office了。请参阅此CodeProject文章:

创建基本带有Open XML的Excel工作簿 [ ^ ]。



以下是Microsoft在某些设置中禁止使用互操作的警告:

http://support.microsoft.com/default.aspx?scid=kb;EN-美国; q257757#kb2 [ ^ ],

http://support.microsoft。 com / kb / 257757 / zh-CN [ ^ ]。



另见我过去的答案:

如何从MS Visual Studio 2010中的添加引用添加microsoft excel 15.0对象库 [ ^ ],

Microsot office Interop [ ^ ]。



如果您仍想使用Office Interop,请参阅我之前的回答:http://msdn.microsoft.com/en-us/library/dd264733.aspx [ ^ ]。



-SA


How i Do resolved this Error???

Aaqib

解决方案

I think you are getting this error to create a excel file

try to create excel like

using Excel=Microsoft.Office.Interop.Excel;
using System.Reflection



public void CreateExcel( string fileName)
{
Object missing = Missing.Value;
Microsoft.Office.Interop.Excel.Application m_objExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks m_objWorkBooks = m_objExcel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook m_objWorkBook = m_objWorkBooks.Add(true);
Microsoft.Office.Interop.Excel.Sheets m_objWorkSheets = m_objWorkBook.Sheets; ;
Microsoft.Office.Interop.Excel.Worksheet m_objWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)m_objWorkSheets[1];
m_objWorkBook.SaveAs(fileName, missing, missing, missing, missing, missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
missing, missing, missing, missing, missing);
m_objWorkBook.Close(false,missing,missing);
m_objExcel.Quit();
}


You might 1) have no Excel installed; 2) it is installed, but you did not reference the interop assembly; 3) you referenced it, but you should use proper (fully-qualified, full) type name or use using directive to resolve its full name, with namespace.

I would rather advice to use Open XML SDL, then you won't need Office installed. Please see this CodeProject article:
Creating basic Excel workbook with Open XML[^].

Here are the Microsoft warnings against using interop in some settings:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

See also my past answers:
How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^],
Microsot office Interop[^].

If you still want to use Office Interop, please see my past answer: http://msdn.microsoft.com/en-us/library/dd264733.aspx[^].

—SA


这篇关于为什么我应该得到这个错误?名称'Excellibrary'在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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