I am using EPPLUS library for creating excel file with a data table. I have such column in my stored procedure: emp_name, sales, INR, marketing, INR But in excel file it generates column name like with column name like emp_name, sales, INR, marketing, INR1 etc. How do I prevent that to print whatever column name in the data table or any other configurations that I am missing?
Code:
string BasePath = ConfigurationManager.AppSettings["BasePath"];
string fileName = Guid.NewGuid().ToString() + ".xlsx";
string FilePath = BasePath + fileName;
using (ExcelPackage excel = new ExcelPackage())
{
ExcelWorksheet ws =
excel.Workbook.Worksheets.Add("WorkingReport");
ws.Cells["A1"].LoadFromDataTable(data,false);
ws.Row(1).Style.Font.Bold = true;
ws.Column(1).Width = 10;
ws.Column(2).Width = 20;
ws.Column(3).Width = 20;
ws.Column(4).Width = 20;
FileInfo excelFile = new FileInfo(FilePath);
ws.Protection.IsProtected = false;
excel.SaveAs(excelFile);
}