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 ?
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();
The answer for me was to mark Embed Interop types as false. See this question.
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();
You need to declare the variable as Microsoft.Office.Interop.Excel.Application
, but instantiate it as Microsoft.Office.Interop.Excel.ApplicationClass
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With