Skip to content

Instantly share code, notes, and snippets.

@derans
Created September 23, 2012 22:10
Show Gist options
  • Save derans/3773221 to your computer and use it in GitHub Desktop.
Save derans/3773221 to your computer and use it in GitHub Desktop.
Specific Columns & Formatting ExportToExcel
public ActionResult ExportToExcel()
{
var records = _getSampleInfoQuery.Execute();
var columns = new[]
{
ExcelColumnDefinition.Create<SampleInfo>(x => x.College),
ExcelColumnDefinition.Create<SampleInfo>(x => x.Amount, ExcelFormat.Money),
ExcelColumnDefinition.Create<SampleInfo>(x => x.CreatedDate, ExcelFormat.Date, "Date"),
ExcelColumnDefinition.Create<SampleInfo>(x => x.CreatedBy),
ExcelColumnDefinition.Create<SampleInfo>(x => x.CreatedDate, ExcelFormat.Time, "Time"),
ExcelColumnDefinition.Create<SampleInfo>(x => x.PercentageExample, ExcelFormat.Percent),
};
return new ExcelFileResult<SampleInfo>(records) {ColumnDefinitions = columns};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment