Search code examples
c#excelepplusdatetime-parsing

C# How to copy the content of excel as you see (for example: date time as you see is 12/31/2018, excel content is a number like 43465)


I am having a problem with parsing excel content to datetime type.

In my country, there are just two cultureinfo to use: "vi-VN" (dd/MM/yyyy) and "us-US" (MM/dd/yyyy).

For some cases I test, both DateTime.Parse with cultureinfo above throwing error "String is not recognized as a valid datetime".

I want to use DateTime.ParseExact instead of above approach. In order to do this, I must get a string like "12/31/2018". But when I use Epplus, it reads the content of the cell as a number 43465. This way, I cannot parse use DateTime.ParseExact.

Any here know how to read the excel as you see on the screen ?

Thank you.


Solution

  • DateTime.FromOADate(Double) Method

    var dateTime = DateTime.FromOADate(43465);