【问题标题】:Epplus Cell with DateTime type not recognized无法识别日期时间类型的 Epplus 单元
【发布时间】:2018-06-27 13:54:30
【问题描述】:

我对 DateTime 格式有疑问。 单元格具有以下 NumberFormat "[$-F800]dddd\,\ mmmm\ dd\,\ yyyy" 但它不被识别为 DateTime。

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

如何获取单元格的DataType?

最好的问候

【问题讨论】:

标签: epplus epplus-4


【解决方案1】:

不要使用Value,使用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"));
}

ab 的值都是 12/31/2018 12:00:00 AM

(CultureInfo 在 System.Globalization 命名空间中)。

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 2014-12-30
    • 2015-10-10
    • 2013-03-03
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2018-06-11
    相关资源
    最近更新 更多