用的是poi 3.7版本,主要 是想给一个已经存在的excel文件修改,代码如下:
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.io.FileInputStream;
import java.io.IOException;
public class PoiTest {
static public void main(String[] args) throws Exception {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("d:/test.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheet("sheet1");
HSSFRow row = sheet.getRow(0); //行
HSSFCell cell = row.getCell((short) 0); //列
if(cell==null){
System.out.println("null");
}
else{
System.out.println(" not null");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
调试发现,如果test文件指定的第1行第1列单元格有数据,那么运行正常.
如果test文件指定的第1行第1列单元格没有任何数据,那么程序运行完语句"HSSFCell cell = row.getCell((short) 0); "马上就发生了异常错误,根本就没有进入到下一判断语句.请问: 为什么会这样,应该如何解决??
抛出异常为: com.sun.jdi.InvocationException occurred invoking method.