24

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 ?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Naues
  • 241
  • 1
  • 2
  • 3

6 Answers6

35

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
  • 34,502
  • 9
  • 78
  • 118
5

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

Community
  • 1
  • 1
Matan Melamed
  • 86
  • 1
  • 5
3

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();
Adi Lester
  • 24,731
  • 12
  • 95
  • 110
santosh Kundkar
  • 149
  • 1
  • 3
1

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

iandisme
  • 6,346
  • 6
  • 44
  • 63
1
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.

JMD
  • 7,331
  • 3
  • 29
  • 39
0

For MS Office 2016 you need to use the following no dramas

Excel.Application oExcel = new Excel.Application();
afr0
  • 848
  • 1
  • 11
  • 29