How to format cell using EPPlus package in C# MVC

Posted on September 4, 2018 by Suresh Kamrushi in C#

EPPlus is a great package used in C# to export and import excel files. Here I am sharing how we can format data while exporting data to excel.

1) Formatting text, possible values:”Italic”, “Bold”

sheetcreate.Cells[1, 1].Style.Font.Bold = true;

2) For merging cells

sheetcreate.Cells[1, 1, 1, 5].Merge = true; //Address "A1:A5"

3) Setting up border for cells

sheetcreate.Cells[1, 1].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);

4) Setting up cell alignment. It can be “Center”, “Right” and “Left”.

 sheetcreate.Cells[1, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

5) Setting up background color

 sheetcreate.Cells[1, 1].Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#e0e0e0"));

6) To avoid word wrap in excel use blow function. It should be written after creation of excel sheet.

sheetcreate.Cells.AutoFitColumns();
Tagged as ,