从Apache POI 3.2中读取Excel(XLS)数据中的不同格式

我正在尝试使用JDK 1.4和Apache POI 3.2来读取XLS(2007格式)文件。 我已经有几行文本已经是文本格式(右键单击 – >格式单元格 – >文本)。

我手动在文件中添加了几行,没有任何文本格式。假设新添加的行的格式是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