Install-Package Dexiom.EPPlusExporter
Please review the Wiki pages on how to use Dexiom.EPPlusExporter.
Let's say you want to dump an array or a list of objects to Excel (without any specific formatting).
This is what you would do:
//create the exporter
var exporter = EnumerableExporter.Create(employees);
//generate the document
var excelPackage = exporter.CreateExcelPackage();
//save the document
excelPackage.SaveAs(new FileInfo("C:\\example1.xlsx"));
Quick customization can be accomplished by using the fluent interface like this:
var excelPackage = EnumerableExporter.Create(employees)
.DefaultNumberFormat(typeof(DateTime), "yyyy-MM-dd") //set a default format for all DateTime columns
.NumberFormatFor(n => n.DateOfBirth, "yyyy-MMM-dd") //set a specific format for the "DateOfBirth"
.Ignore(n => new { n.UserName, n.Email }) //remove 2 columns from the output
.TextFormatFor(n => n.Phone, "Cell: {0}") //add a prefix to the value
.StyleFor(n => n.DateContractEnd, style =>
{
style.Fill.Gradient.Color1.SetColor(Color.Yellow);
style.Fill.Gradient.Color2.SetColor(Color.Green);
}) //the cells in this columns now have a gradiant background
.CreateExcelPackage();
- Available customizations:
- Ignore is used to skip a column when generating the document
- DefaultNumberFormat is used to specify a default display format for a specific type
- NumberFormatFor is used to set a specific format (just like you would using Excel)
- TextFormatFor is used to convert a value to text
- StyleFor is used to alter the style for a specific column
Copyright (c) Consultation Dexiom. All rights reserved.
Licensed under the MIT License.