简体   繁体   中英

Error: Type 'ExcelPackage' is not defined while using EPPLUS dll to export to excel

I am new to Windows Forms, I have a requirement to export a DataTable to excel. I found out that I need to have to Microsoft Office installed on my machine to use Microsoft.Office.Interop.Excel but I do not have that installed.

I came across EPPLUS. I downloaded and added the reference to the dll in my project. But problem is that it still shows me error.

I used Imports OfficeOpenXml but this one gives me an error. When I add reference once again, the error disappears and the ExcelPackage (where I was getting error gets color , same as a any keyword.) But when I build the application or run the application it again gives me the same error.

using (ExcelPackage pck = new ExcelPackage(newFile))
{
  ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Accounts");
  ws.Cells["A1"].LoadFromDataTable(dataTable, true);
  pck.Save();
}

Try to change the Target .NET Framework:

  1. On the Project menu, click ProjectName Properties .
  2. In the left column of the property pages window, select the Application tab
  3. In the Target Framework drop-down list, select the " .NET Framework 4 ". In the verification dialog box that appears, choose the Yes button.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM