Send excel email attachment c#

Here is a complete working example of how to attach an EPPlus generated Excel file to an email message as attachment. But you have to use a MemoryStream to attach a file to a message. //create a new memorystream for the excel file MemoryStream ms; //create a new ExcelPackage using (ExcelPackage package = new ExcelPackage()) … Read more

Adding images into Excel using EPPlus

I’m not sure if this is the best solution but definetly a workaround for your problem. Here’s what I did: ExcelPackage package = new ExcelPackage(); var ws = package.Workbook.Worksheets.Add(“Test Page”); for (int a = 0; a < 5; a++) { ws.Row(a * 5).Height = 39.00D; } for (int a = 0; a < 5; a++) … Read more

EPPlus number format

Here are some number format options for EPPlus: //integer (not really needed unless you need to round numbers, Excel will use default cell properties) ws.Cells[“A1:A25”].Style.Numberformat.Format = “0”; //integer without displaying the number 0 in the cell ws.Cells[“A1:A25”].Style.Numberformat.Format = “#”; //number with 1 decimal place ws.Cells[“A1:A25”].Style.Numberformat.Format = “0.0”; //number with 2 decimal places ws.Cells[“A1:A25”].Style.Numberformat.Format = “0.00”; … Read more

C# create/modify/read .xlsx files

With EPPlus it’s not required to create file, you can do all with streams, here is an example of ASP.NET ashx handler that will export datatable into excel file and serve it back to the client : public class GetExcel : IHttpHandler { public void ProcessRequest(HttpContext context) { var dt = DBServer.GetDataTable(“select * from table”); … Read more

Excel to DataTable using EPPlus – excel locked for editing

I see, that’s what i’ve posted recently here(now corrected). It can be improved since the ExcelPackage and the FileStream(from File.OpenRead) are not disposed after using. public static DataTable GetDataTableFromExcel(string path, bool hasHeader = true) { using (var pck = new OfficeOpenXml.ExcelPackage()) { using (var stream = File.OpenRead(path)) { pck.Load(stream); } var ws = pck.Workbook.Worksheets.First(); DataTable … Read more

Export DataTable to Excel with EPPlus

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.