tags:

views:

1178

answers:

3

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 ?

+3  A: 

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();
Dave Swersky
A: 

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

iandisme
+1  A: 
Excel.Application = new Excel.ApplicationClass();

Note the leading Excel.Application, not Excel.ApplicationClass.

Also note, this is straight out of the MSDN page for ApplicationClass. Did you hit F1?

JMD