I have an ActionResult (in an MVC 5 website) that successfully uses Epplus to export a data set to an Excel document.
In the ActionResult code block, I use code like this to format the column as a short date. WIthout this code, the date column appears as int values.
// format date columns as date
worksheet.Column(6).Style.Numberformat.Format =
DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
However, in the Model, I already have this defined as an attribute. It works great on the View page, but doesn't format the column as a short date -- hence, the code shown above.
[Column(TypeName = "date")]
[DisplayName("Exit Date")]
**[DisplayFormat(DataFormatString = "{0:d}")]**
public DateTime ExitDate { get; set; }
To provide further context, I load my worksheet from a collection.
worksheet.Cells["A5"].LoadFromCollection(Collection: exportQuery, PrintHeaders: true);
Is there a way that I can extend LoadFromCollection so that that the worksheet not only loads the Collection content, but also the formatting attributes that exist in the model? The "DisplayName" attributes are collected, so is there a way to also collect "DisplayFormat" attributes without having to write separate code?