This project has moved and is read-only. For the latest updates, please go here.

How to apply Date Format for Excel Cell

Oct 3, 2011 at 1:54 PM

Hi,

I am using EPPlus for excel export purpose. I want to apply date format for cell . How should i do it. I have tried this way

ws.Cells[rowNum, colNum].Style.Numberformat.Format = "DD/MM/YYYY"; But its not working. Still the cell have number format.

Oct 4, 2011 at 9:35 PM

That should work. Make sure that the value of the cell isn't a string (have a look at the FAQ and the samples).

Oct 5, 2011 at 11:01 AM

Hi,

when i implement this statement ws.Cells[rowNum, colNum].Style.Numberformat.Format = "DD/MM/YYYY".

Cell value gets display as "10/05/2011". But once you double click on that cell its value get converted in number as 40821.00.

As cell format is Number and not Date Format.

Could u please suggest what to do?

Oct 9, 2011 at 6:31 PM

The standard date format is mm-dd-yy, it will show different formats depending on your regional settings.

If its not what you want read the FAQ how to check the numberformat of an existing xlsx file.

Oct 10, 2011 at 10:07 AM
Edited Oct 10, 2011 at 10:08 AM

Got solution for my Problem as below, it set custom format for that field... but its consider as Date..... :)

We need to set Formula field instead of Value field.

ws.Cells[rowNum, colNum].Formula = "=DATE(2011,10,4)";

ws.Cells[rowNum, colNum].Style.Numberformat.Format = "DD/MM/YYYY";

Nov 10, 2014 at 2:53 PM
This does not store the value as a date, but rather a number. See https://epplus.codeplex.com/discussions/571553