Click here to Skip to main content
15,885,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How i Do resolved this Error???

Aaqib
Posted
Comments
Dilan Shaminda 22-Aug-14 2:46am    
we can't predict what you have written in your source code.Please post your code here.

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

try to create excel like

C#
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();
}
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900