Reputation: 235
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);
} }
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?
Upvotes: 2
Views: 7058
Reputation: 48326
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
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
Upvotes: 5