未验证 提交 d9f1a231 编写于 作者: 抵不住_寂寞's avatar 抵不住_寂寞 提交者: GitHub

解决 excel 内容为公式类型时 直接cell.ToString 会报错。 必须获取对应类型的值 (#210)

Co-authored-by: Ncheny <cheny@airflys.com>
上级 e57dc050
......@@ -343,17 +343,46 @@ namespace ET
private static string GetCellString(ISheet sheet, int i, int j)
{
return sheet.GetRow(i)?.GetCell(j)?.ToString() ?? "";
IRow _irow = sheet.GetRow(i);
if(_irow != null)
{
return GetCellString(_irow, j);
}
return "";
}
private static string GetCellString(IRow row, int i)
{
return row?.GetCell(i)?.ToString() ?? "";
ICell _icell = row.GetCell(i);
if (_icell != null)
{
return GetCellString(_icell); ;
}
return "";
}
private static string GetCellString(ICell cell)
{
return cell?.ToString() ?? "";
if (cell != null)
{
if(cell.CellType == CellType.Numeric || (cell.CellType == CellType.Formula && cell.CachedFormulaResultType == CellType.Numeric))
{
return cell.NumericCellValue.ToString();
}
else if (cell.CellType == CellType.String || (cell.CellType == CellType.Formula && cell.CachedFormulaResultType == CellType.String))
{
return cell.StringCellValue.ToString();
}
else if (cell.CellType == CellType.Boolean || (cell.CellType == CellType.Formula && cell.CachedFormulaResultType == CellType.Boolean))
{
return cell.BooleanCellValue.ToString();
}
else
{
return cell.ToString();
}
}
return "";
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册