I'm using EPPlus to generate Excel files, in DAL I'm populating DataTable, filling data into table, and passing table to Presentation Layer. From there I'm using LoadFromDataTable() method to generate Excel file.
Everything works fine, except that I want to set one of the column's type to Date. I tried to set Column type of my DataTable toDate and than pass DataTable to Presentation Layer, but it seems EPPlus either, ignored it, or didn't recognize, because when I'm opening generated Excel file, cell's type is Number.
If I manually Format Cells and set Type to Date, Excel shows correct dates. So how can I achieve this ?
Format = "yyyy-mm-dd"; ws. Cells[3, 1]. Value = new DateTime(2014,10,5); ws.
EPPlus is a very helpful open-source 3rd party DLL for writing data to excel. EPPlus supports multiple properties of spreadsheets like cell ranges, cell styling, charts, pictures, shapes, comments, tables, protection, encryption, pivot tables, data validation, conditional formatting, formula calculation, etc.
What is EPPlus? A library to manage Excel spreadsheets. EPPlus is a . NET library, which reads and writes Excel 2007/2010 or higher files, using Open Office XML format. It supports .
You do need the DataTable column to have the right type but you also need to modify the column or cell's Style.Numberformat.Format property.
Say you have an ExcelWorksheet named ws:
ws.Column(1).Style.Numberformat.Format = "yyyy-mm-dd"; //OR "yyyy-mm-dd h:mm" if you want to include the time!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With