如题,其他数据都能取到,但凡有公式的单元格里的数据都取不到
通过]执行公式获取值
1
1 switch (cell.CellType) 2 { 3 case CellType.BLANK: 4 dataRow[j] = string.Empty; 5 break; 6 case CellType.BOOLEAN: 7 dataRow[j] = cell.BooleanCellValue; 8 break; 9 case CellType.NUMERIC: 10 if (DateUtil.IsCellDateFormatted(cell))//日期 11 { 12 dataRow[j] = cell.DateCellValue; 13 } 14 else 15 { 16 dataRow[j] = cell.NumericCellValue; 17 } 18 break; 19 case CellType.STRING: 20 dataRow[j] = cell.StringCellValue.Trim(); 21 break; 22 case CellType.ERROR: 23 dataRow[j] = cell.ErrorCellValue; 24 break; 25 case CellType.FORMULA://公式 26 try 27 { 28 HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook); 29 e.EvaluateInCell(cell); 30 dataRow[j] = cell.ToString(); 31 } 32 catch 33 { 34 if (DateUtil.IsCellDateFormatted(cell))//日期 35 { 36 dataRow[j] = cell.DateCellValue; 37 } 38 else 39 { 40 dataRow[j] = cell.NumericCellValue; 41 } 42 } 43 break; 44 default: 45 dataRow[j] = cell.ToString(); 46 break; 47 }