日期:2014-05-18  浏览次数:20799 次

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 crat