利用NPOI导入Excel时单元格类型CellType为公式Formula时的处理方式
利用递归进行重复判断处理
代码
Action<CellType> action = null;
action = ct =>
{
switch (ct)
{
case CellType.Numeric:
if (DateUtil.IsCellDateFormatted(row.GetCell(j)))
{
dataRow[j] = row.GetCell(j).DateCellValue.ToString("yyyy-MM-dd");
}
else
{
dataRow[j] = row.GetCell(j).NumericCellValue;
}
break;
case CellType.String:
dataRow[j] = row.GetCell(j).StringCellValue.Trim();
break;
case CellType.Boolean:
dataRow[j] = row.GetCell(j).BooleanCellValue;
break;
case CellType.Error:
dataRow[j] = HSSFErrorConstants.GetText(row.GetCell(j).ErrorCellValue);
break;
case CellType.Formula:
action(row.GetCell(j).CachedFormulaResultType);
break;
default:
dataRow[j] = row.GetCell(j).ToString().Trim();
break;
}
};
action(row.GetCell(j).CellType);