POI 导出excel 时Cannot get a error value from a numeric cell

LCG454872006 2013-12-25 09:03:23

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的时候报的错,谁遇见过这个错误
...全文
921 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoqiuwyh 2013-12-25
  • 打赏
  • 举报
回复
类型不正确,你应该先判断类型,再取值。
tony4geek 2013-12-25
  • 打赏
  • 举报
回复
应该是类型问题。debug 看看数据。。
一条大红龙 2013-12-25
  • 打赏
  • 举报
回复
应该是格子里是数字类型,但是没用数字类型去取
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;
    		}
这样试试

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧