Excel Export
For this I use EP Plus Excel Export. Add the EP Plus library from Nuget to your project. Then add this class to your project.
ExcelExport.cs
Try
And use it on MVC:
public ActionResult ExportToExcel(string cid) { var customerList = new List<DtoCustomer>(); customerList = CustomerFactory.Gets(); ExcelExport.EpplusExportToExcelFromObjectList(customerList.ToList<object>(), "Customer List", true); return null; }
You can also determine which column indicates the name in the Excel document. you need to create an attribute class for this.
ExportAttribute
using System.Attribute; public class ExportAttribute : Attribute { public string DisplayName { get; set; } public bool IsVisible { get; set; } }
Class and implementation
Then we implement this attribute for your class:
public class DtoCustomer { [ExportAttribute(DisplayName = "#", IsVisible = false)] public int ID { get; set; } [ExportAttribute(DisplayName = "Customer Name", IsVisible = true)] public string Name{ get; set; } [ExportAttribute(DisplayName = "Customer Surname", IsVisible = true)] public string Surname { get; set; } }
source share