I'm new to the Apache POI, but what I want to do is read though an Excel file (.xls) and put that into a ArrayList to store so that I can later manipulate. I can get the whole sheet, but my problem is just that: I get the whole dang sheet (~54183 rows).
I want to skip over the cells that are blank, which is of type 3. For some reason, when I system.out.print the ArrayList, it has all the blank cells in there.
Is there a way to skip over those and not add them to the ArrayList I'm trying to create?
I have the following bit of code:
public ArrayList readExcelFile(String filePath) throws IOException {
ArrayList cellVectorHolder = new ArrayList();
try {
FileInputStream inputFile = new FileInputStream(filePath);
POIFSFileSystem myFileSystem = new POIFSFileSystem(inputFile);
HSSFWorkbook wkbk = new HSSFWorkbook(myFileSystem);
wb = wkbk;
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
HSSFSheet wkSheet = wkbk.getSheetAt(i);
for (Row row : wkSheet) {
ArrayList cellVector = new ArrayList();
for (Cell cell : row) {
if(cell.getCellType() != 3){
cellVector.add(cell);
}
}
cellVectorHolder.add(cellVector);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return cellVectorHolder;
}
Don't mind the ArrayList names...I was using Vectors until I finally discovered they were depreciated since 1.2 or something like that.