我需要对excel上的所有批注进行删除操作
代码如下:
for(Iterator<HSSFCell> cellIt = row.cellIterator(); cellIt.hasNext();){
HSSFCell cell = cellIt.next();
if(cell != null ){
if(cell.getCellComment() != null){
cell.setCellComment(null);
}

}
}奇怪的是 我明明debug到那个cell是有comment的 而且那个cell里面有值 在if(cell != null ){ 这行 cell的确不为空 而进入if(cell.getCellComment() != null){ 却抛nullpoint错误 ,请各位用过poi的同学帮忙 十分感谢

解决方案 »

  1.   

    抛错如下:
    java.lang.NullPointerException
    at org.apache.poi.hssf.usermodel.HSSFCell.findCellComment(HSSFCell.java:1021)
    at org.apache.poi.hssf.usermodel.HSSFCell.getCellComment(HSSFCell.java:952)
    at com.**.util.xls.ExcelCellClear.clearComments(ExcelCellClear.java:35)
      

  2.   

    if(cell.getCellComment() != null){
       cell.setCellComment(null);
    }
    應該getCellComment()方法報錯了。
      

  3.   

    if(cell.getCellComment() != null){
    换成
    if( null !=cell.getCellComment()){
    就不会有空指针了 不过具体你是否能取到注释的值 不是很清楚
      

  4.   

    问题解决了 是poi底层的txo为null 改源码了