Skip to content

Supported Expresssion Types

Jonathan Paré edited this page Feb 26, 2017 · 1 revision

To keep things simple and avoid code repetition, EPPlusExporter support both MemberExpression and NewExpression

MemberExpression: n => n.Prop1
NewExpression: n => new { n.Prop1, n.Prop2 }

Usage example

var data = new[]
{
	new { TextValue = "Text #1", DateValue = DateTime.Now, DoubleValue = 10.1, IntValue = 1},
	new { TextValue = "Text #2", DateValue = DateTime.Now, DoubleValue = 10.2, IntValue = 2},
	new { TextValue = "Text #3", DateValue = DateTime.Now, DoubleValue = 10.3, IntValue = 3},
	new { TextValue = "Text #4", DateValue = DateTime.Now, DoubleValue = 10.4, IntValue = 4}
};

//configure the exporter
var exporter = EnumerableExporter.Create(data)
	.NumberFormatFor(n => n.DateValue, "yyyy-mmm-dd") //MemberExpression for single column
	.NumberFormatFor(n => new
	{
		n.DoubleValue,
		n.IntValue
	}, "0.00"); //NewExpression to assign the same format to 2 columns

Output:

Enumerable2