Date Formatting in ClosedXML

Nate Pet picture Nate Pet · Jul 29, 2015 · Viewed 16.7k times · Source

I have date's in an excel sheet that I am reading from. What I like to do is to force the date to be in mm/dd/yyyy Is there a way to do this in Closed XML.

I took at a look https://closedxml.codeplex.com/documentation but could not find how to force or update the date to a certain format.

Answer

Smit Patel picture Smit Patel · Oct 8, 2015

If you want to do it on Specific cell then you have to use

worksheet.Cell(row,column).Style.NumberFormat.Format = "mm/dd/yyyy";

and

If you want to do it on multiple cells then you have to use

worksheet.Range(row,column,row,column).Style.NumberFormat.Format = "mm/dd/yyyy";