我正在尝试使用JDK 1.4和Apache POI 3.2读取XLS(2007格式)文件 . 我已经在文件中有几行TEXT格式化(RIght click-> Format cells - > Text) .

我手动在文件中添加了更多行,没有任何文本格式,假设新添加的行的格式为RAW .

POI无法读取稍后添加的行 . 如果新添加的行也被格式化为TEXT,它只能读取它们 .

代码如下所示:

HSSFSheet sheet = workBook.getSheetAt(sheetno);
int rowStart =  sheet.getFirstRowNum();
//int rowEnd = sheet.getLastRowNum();
int rowEnd =    sheet.getPhysicalNumberOfRows();
for (int rowNum = rowStart; rowNum <= rowEnd; rowNum++)
        {
            HSSFRow row = (HSSFRow) sheet.getRow(rowNum);
            Vector cellStoreVector=new Vector();
            int current = 0, next = 1;

            for (int colNum = row.getFirstCellNum(); colNum < row.getLastCellNum(); colNum++)
            {
                HSSFCell cell = (HSSFCell) row.getCell(colNum);             
                currentCell = cell.getColumnIndex();
                current = cell.getColumnIndex();
                if (current < next)
                {
                    cellStoreVector.addElement(cell);
                }
                else 
                {
                    int loop = current - next;
                    for (int k = 0; k < loop + 1; k++)
                    {
                        cellStoreVector.addElement("");
                        next = next + 1;
                    }
                }
                next = next + 1;                                        
            }
      }

到目前为止我尝试过的事情:

1)使用RowIterator对象,然后使用while循环进行迭代 .

Iterator rowIter = sheet.rowIterator();
while(rowIter.hasNext()) - Results in the same no. of rows being iterated.

2)利用

sheet.getPhysicalNumberOfRows(); and
 sheet.getLastRowNum();- Results in the same no. of rows being iterated.

之前有没有人遇到过与Excel文件类似的问题?任何帮助将不胜感激 .

谢谢,Arihant