-
Notifications
You must be signed in to change notification settings - Fork 16
Export an object
Jonathan Paré edited this page Feb 2, 2017
·
4 revisions
A very basic demonstration.
//create fake data
var data = new { TextValue = "Text #1", DateValue = DateTime.Now, DoubleValue = 10.1, IntValue = 1 };
//create the document
var excelPackage = ObjectExporter.Create(data).CreateExcelPackage();
//save it!
excelPackage.SaveAs(new FileInfo("example1.xlsx"));
Samething with a few customizations.
//create fake data
var data = new { TextValue = "Text #1", DateValue = DateTime.Now, DoubleValue = 10.1, IntValue = 1 };
//configure the exporter
var exporter = ObjectExporter.Create(data)
.TextFormatFor(n => n.TextValue, "Prefix: {0}")
.NumberFormatFor(n => n.DateValue, "yyyy-MM-dd")
.DefaultNumberFormat(typeof(double), "0.00 $")
.Ignore(n => n.IntValue);
exporter.WorksheetName = "MyData"; //set tab name
exporter.TableStyle = TableStyles.Medium2; //set table style
//create the document
var excelPackage = exporter.CreateExcelPackage();
//save it!
excelPackage.SaveAs(new FileInfo("example2.xlsx"));
- Getting started
- Working with:
- Customizations
- Goodies
- Supported Expressions
- DisplayNameAttribute