Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export DataTable to Excel with EPPlus

I want to export a data table to an Excel file with EPPlus. That data table has a property with int type, so I want the same format in the Excel file.

Does anyone know way to export a DataTable like this to Excel?

like image 784
Davood Hanifi Avatar asked Dec 02 '12 13:12

Davood Hanifi


1 Answers

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

That should do the trick for you. If your fields are defined as int EPPlus will properly cast the columns into a number or float.

like image 93
bastianwegge Avatar answered Sep 19 '22 05:09

bastianwegge