Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# -Excel interoperability

Tags:

excel

c#-4.0

I want to call Excel Sheet from C# 4.0 (VS 2010 Express Edition) .

When i declare ,

Microsoft.Office.Interop.Excel.ApplicationClass excel =
    new Microsoft.Office.Interop.Excel.ApplicationClass();

excel.Visible = true;

I receive error as

Interop type 'Microsoft.Office.Interop.Excel.ApplicationClass' cannot be embedded. Use the applicable interface instead.

What is the soultion ?

like image 821
Naues Avatar asked Dec 17 '09 16:12

Naues


4 Answers

Here is a blog post that deals with that. Looks like you need to change

Microsoft.Office.Interop.Excel.ApplicationClass();

to

Microsoft.Office.Interop.Excel.Application();
like image 125
Dave Swersky Avatar answered Oct 31 '22 22:10

Dave Swersky


The answer for me was to mark Embed Interop types as false. See this question.

like image 5
Matan Melamed Avatar answered Oct 31 '22 22:10

Matan Melamed


Solved:

Excel.ApplicationClass derives from Excel.Application interface and one can even instantiate Excel using Excel.Application interface. Rewriting this code as below produces exact same results:

Excel.Application xlapp = new Excel.Application();
like image 3
santosh Kundkar Avatar answered Oct 31 '22 23:10

santosh Kundkar


You need to declare the variable as Microsoft.Office.Interop.Excel.Application, but instantiate it as Microsoft.Office.Interop.Excel.ApplicationClass.

like image 1
iandisme Avatar answered Oct 31 '22 23:10

iandisme