简体   繁体   English

读取Excel文件2010 Apache POI忽略空单元格

[英]Read excel file 2010 apache poi ignoring empty cells

I am having an problem, while java application reading Excel file .xlsx extention, The application is working normally, but in the workbook has many sheets, 1, 2 sheets reading correctly , but when reads 3 sheet, there does not read all the cells and while I opened and checked from Excel file, cell is exists with empty values, but when apache poi reading it the cell is just ignored the empty cells. 我有一个问题,当java应用程序读取Excel文件.xlsx扩展时,该应用程序正常工作,但是在工作簿中有很多工作表,其中1、2个工作表正确读取,但是当读取3个工作表时,没有读取所有单元格当我打开并从Excel文件中检查时,单元格存在空值,但是当apache poi读取该单元格时,该单元格将被忽略。 What is a cause? 原因是什么? Update 更新

 FileInputStream file = new FileInputStream(file_location);
  //this.workbook = new HSSFWorkbook(file);
  this.workbook = new XSSFWorkbook(file);
XSSFSheet mySheet = workbook.getSheetAt(index);
       Iterator rowIter = mySheet.rowIterator();
        while(rowIter.hasNext()){
          XSSFRow myRow = (XSSFRow) rowIter.next();
          Iterator cellIter = myRow.cellIterator();
          ArrayList colStoreArray=new ArrayList();



          while(cellIter.hasNext()){
              XSSFCell myCell = (XSSFCell) cellIter.next();
              colStoreArray.add(myCell);
                                   }
          rowArrayHolder.add(colStoreArray);

        } }

Above the reading excel file, While i checked the Excel file there in one row 20 cells, but while it reads in some rows only 14 rows. 在读取excel文件上方,虽然我在一行中检查了Excel文件20个单元格,但在某些行中却仅读取了14行。 I am using ArrayList, seems here should be problem with the concurrent accessing the ArrayList. 我正在使用ArrayList,似乎这里应该是并发访问ArrayList的问题。 What can be cause? 可能是什么原因?

The iterators only iterate over cells that are defined in the file. 迭代器仅遍历文件中定义的单元格。 If the cell has never been used in Excel, it probably won't appear in the file (Excel isn't always consistent...), so POI won't see it 如果单元格从未在Excel中使用过,则它可能不会出现在文件中(Excel并不总是一致的...),因此POI不会看到它

If you want to make sure you hit every cell, you should lookup by index instead, and either check for null cells (indicating the cell has never existed in the file), or set a MissingCellPolicy to control how you want null and blank cells to be treated 如果要确保击中每个单元格,则应改用索引查找,然后检查空单元格(指示该单元格在文件中不存在),或设置MissingCellPolicy来控制希望空单元格和空白单元格被处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM