当前位置: 代码迷 >> J2EE >> POI 导出excel 时Cannot get a error value from a numeric cell解决办法
  详细解决方案

POI 导出excel 时Cannot get a error value from a numeric cell解决办法

热度:894   发布时间:2016-04-21 21:00:06.0
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>)

用Poi的SXXFWorkbook导出excel2007的时候报的错,谁遇见过这个错误

------解决方案--------------------
应该是格子里是数字类型,但是没用数字类型去取
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;
     }

这样试试
------解决方案--------------------
应该是类型问题。debug 看看数据。。
------解决方案--------------------
类型不正确,你应该先判断类型,再取值。
  相关解决方案