读取Excel文件2010的Apache POI忽略空白单元格 [英] Read excel file 2010 apache poi ignoring empty cells

查看:1248
本文介绍了读取Excel文件2010的Apache POI忽略空白单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,而java应用程序读取Excel文件的.xlsx延伸,该应用程序正常工作,但在工作簿中有很多表,1,2张正常阅读,但是当读取3片,但不读存在空值的所有单元格,而我打开和Excel文件检查,细胞,但是当Apache POI读它的细胞只是忽略空单元格。是什么原因?
更新

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. 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);

        } }

阅读上面的excel文件,当我检查了Excel文件中有一排20个细胞,但在它的某些行只有14行读取。我使用的ArrayList,似乎这里应与并发访问ArrayList的问题。有什么可以引起?

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. I am using ArrayList, seems here should be problem with the concurrent accessing the ArrayList. What can be cause?

推荐答案

的迭代器只能遍历文件中定义的细胞。如果细胞从未在Excel中使用,它可能不会出现在文件中(Excel中并不总是一致...),所以POI不会看到它

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

如果你想确保你打的每一个细胞,你应该索引查找,而是和任何检查空细胞(表示从来没有在文件中存在的细胞),或设置 MissingCellPolicy 来控制你想怎么来对待空和空白单元格

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

这篇关于读取Excel文件2010的Apache POI忽略空白单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆