Search code examples
c#epplusdate-formatting

when using EPPlus in C#, how to export a globally clear date format?


I am using EPPlus which is an excellent Excel wrapper to use from C#. I am using it in an asp.net-mvc site and I ran into one strange issue. I want to export a cell with a date format that will work for everyone globally. My web server is in London but i have users all around the world.

What is the correct way to format the Numberformat so the date shows up as something like "12-Apr-2016" (so there is no confusion what is the day and what is the month)

_currentWorksheet.Cells["A2"].Value = myDate;
_currentWorksheet.Cells["A2"].Style.Numberformat.Format = "dd-MMM-yyy";

but it doesn't seem to export correctly.

What is the right syntax for formatting dates that show up in excel globally and could not be confused?


Solution

  • Set the correct user locale, which should make things "globally clear" for them:

    _currentWorksheet.Cells["A2"].Style.Numberformat.Format =
    System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
    

    System.Globalization was made for cases like this.