日期:2014-05-17  浏览次数:20746 次

读excel文档中的格子空白内容出错,求助
读excel文档中的格子内容,String str=cell.getStringCellValue();
如果格子中内容为空时就会出错.(用的是poi库)

short cellNum = row.getLastCellNum();  //执行后cellNum=10
for (int i=0;i<cellNum;i++){
cell = row.getCell(i);
String str=cell.getStringCellValue();  //第5格子里内容为空,就会出错
rowlist.add(str);
}
java.lang.NullPointerException
at com.chinatel.fyrui.pubTool.PubExcel.Readrow(PubExcel.java:66)
at com.chinatel.fyrui.custroom.servaddrUpload.doPost(servaddrUpload.java:79)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:619)
Excel String 空白 poi

------解决方案--------------------
恭喜楼主 很快的解决问题了
------解决方案--------------------
引用:
已经明白了,空白内容cell会是空,加个判断cell是否为空就成功了.