[英]Excel Sheet Reading - ClosedXML - Date shown as Number
I have an excel sheet which i am trying to parse.我有一个我正在尝试解析的 excel 表。 All works correctly except when i have a date eg
01-Nov-2016
.一切正常,除非我有一个日期,例如
01-Nov-2016
。 When trying to read this value via _value = cell.Value.ToString();
当试图通过
_value = cell.Value.ToString();
读取这个值时_value = cell.Value.ToString();
it is returning just a number.它只返回一个数字。
After the sheet has been parsed the value 4426979
is displayed.分析工作表后,将显示值
4426979
。
When I debug the codebase the cell.Value
equals [$-4426979]d-mmm-yy
.当我调试代码库时,
cell.Value
等于[$-4426979]d-mmm-yy
。
has anyone encountered this issue?有没有人遇到过这个问题? if so, How do you fix it?
如果是这样,你如何解决它?
the full Function is:完整的功能是:
protected string GetCellContents(IXLCell cell)
{
string _value = string.Empty;
if (cell.HasFormula)
{
_value = cell.ValueCached.ToString();
}
else
{
_value = cell.Value.ToString();
}
return _value;
}
你试过用 .ToString("dd-MMM-yyyy") 替换 .ToString() 吗?
You can try this:你可以试试这个:
string strValue = cell.ValueCached.ToString();
double doubleValue = double.Parse(strValue); // or use double.TryParse if you need
DateTime dateTimeValue = DateTime.FromOADate(doubleValue);
_value = dateTimeValue.ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.