0

I have a problem with the DateTime format. A cell has the following NumberFormat "[$-F800]dddd\,\ mmmm\ dd\,\ yyyy" but it is not recognized as DateTime.

if (cells.Value is DateTime){ var dateTime = DateTime.Parse(cells.Value.ToString()); }

How can i Get the DataType of Cell?

Best Regards

Tricinty
  • 63
  • 6

1 Answers1

0

Do not use Value, use Text:

using (var package = new ExcelPackage())
{
    var worksheet = package.Workbook.Worksheets.Add("Sheet 1");
    worksheet.Cells[1, 1].Value = "12/31/2018"; // en-US culture 
    worksheet.Cells[1, 2].Value = "31.12.2018"; // de-CH culture

    // For current culture
    DateTime a = DateTime.Parse(worksheet.Cells[1, 1].Text); 

    // For culture other than the current one
    DateTime b = DateTime.Parse(worksheet.Cells[1, 2].Text, new CultureInfo("de-CH"));
}

Both a and b have a value of 12/31/2018 12:00:00 AM.

(CultureInfo is in System.Globalization namespace).