I am trying to create an excel file form c# application.
my code is as follows,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
public class ExcelFileCreation
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
***xlApp = new Excel.ApplicationClass();***
xlWorkBook = xlApp.Workbooks.Add(misValue);
//and further lines of code.....
}
I am getting the following error in the highlighted line above as,
Interop type 'Microsoft.Office.Interop.Excel.ApplicationClass' cannot be embedded. Use the applicable interface instead.
please help me out of this problem!
Use Excel.Application
instead of Excel.ApplicationClass
xlApp = new Excel.Application();
Update: You are referencing an interop assembly with "Embed Interop Types" set to true
. According to this post Class
types contain metadata and code, while interfaces only contain metadata. It is safe to embed metadata but not anything that can potentially contain executable code.
Replace
xlApp = new Excel.ApplicationClass();
with
xlApp = new Excel.Application();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.