I am new to Apache POI, but what I want to do is read through an Excel file (.xls) and put it in an ArrayList for storage so that I can later manipulate. I can get the whole sheet, but my problem is that: I get the whole dang sheet (~ 54183 lines).
I want to skip cells that are empty, which are of type 3. For some reason, when I have a system.out.print ArrayList, it has all the empty cells.
Is there a way to skip them 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;
}
Ignore the names of ArrayList ... I used vectors until I found that they were discounted with 1.2 or something like that.
source
share