POI 导出excel 时Cannot get a error value from a numeric cell
java.lang.IllegalStateException: Cannot get a error value from a numeric cell
at org.apache.poi.xssf.streaming.SXSSFCell.typeMismatch(SXSSFCell.java:845)
at org.apache.poi.xssf.streaming.SXSSFCell.getErrorCellValue(SXSSFCell.java:487)
at org.apache.poi.xssf.streaming.SXSSFCell.convertCellValueToString(SXSSFCell.java:895)
at org.apache.poi.xssf.streaming.SXSSFCell.setType(SXSSFCell.java:764)
at org.apache.poi.xssf.streaming.SXSSFCell.ensureType(SXSSFCell.java:721)
at org.apache.poi.xssf.streaming.SXSSFCell.setCellType(SXSSFCell.java:106)
at com.zx.common.utils.msoffice.NewExcelHandle$StyleUtil.setCellValue(NewExcelHandle.java:222)
at com.zx.common.utils.msoffice.NewExcelHandle$StyleUtil.setCellBorder(NewExcelHandle.java:456)
at com.zx.outstock.service.OutStockService.WriteExcelFirstOutStockPhone(OutStockService.java:346)
at com.zx.outstock.service.OutStockService.expAllLedgerDo(OutStockService.java:1495)
at com.zx.outstock.service.OutStockService$$FastClassByCGLIB$$2fa33f31.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at com.zx.outstock.service.OutStockService$$EnhancerByCGLIB$$fbba495b.expAllLedgerDo(<generated>)
switch (cell.getCellType()) {
case Cell.CELL_TYPE_BLANK:
ret = "";
break;
case Cell.CELL_TYPE_BOOLEAN:
ret = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_ERROR:
ret = null;
break;
case Cell.CELL_TYPE_FORMULA:
Workbook wb = cell.getSheet().getWorkbook();
CreationHelper crateHelper = wb.getCreationHelper();
FormulaEvaluator evaluator = crateHelper.createFormulaEvaluator();
ret = getCellValue(evaluator.evaluateInCell(cell));
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
Date theDate = cell.getDateCellValue();
ret = simpleDateFormat.format(theDate);
} else {
ret = NumberToTextConverter.toText(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_STRING:
ret = cell.getRichStringCellValue().getString();
break;
default:
ret = null;
}