无法使用Java中的HSSF工作簿从Excel工作表中读取单元格值

时间:2018-07-02 10:03:13

标签: apache-poi poi-hssf hssf

我有一个包含以下虚拟数据的Excel工作表

UID     ROLL NO.    NAME
16004   1          fgh
16005   2          fhg
16006   3          dfg
16018   4          dfgdf
16029   5          sd

我写了一个代码,可以从excel读取数据并将其插入数据库。在阅读时,我只能阅读第一列。在读取其他列的值时,我得到的是空值。

这是代码。

cell = row.getCell(0);
System.out.println(cell.getNumericCellValue());//I am able to print this

cell = row.getCell(1);
System.out.println(cell);// here i am getting null
System.out.println(cell.getStringCellValue());// NUll pointer exception
                                              // Even get numeric value 
                                  //doesn't work as the cell itself is null.

cell = row.getCell(2); 
System.out.println(cell.getStringCellValue());//Here also I am getting Null 
                    //pointer exception (if the previous code is commented)

有人可以帮我吗?

0 个答案:

没有答案