my excel file has 4 rows and 2 columns like with continuous values having 3row 1st column as blank value like given below
phone plan
------------------
85366667777 PLATINUM
85367890000 GOLD
85362524232 SILVER
null SILVER
85362522436 DIAMOND
public List<List<String>> readExcelFile(String fileName) {
try {
FileInputStream fileInputStream = new FileInputStream(fileName);
POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream);
HSSFWorkbook workBook = new HSSFWorkbook(fsFileSystem);
HSSFSheet hssfSheet = workBook.getSheetAt(0);
Iterator<Row> rowIterator = hssfSheet.rowIterator();
boolean headerRow = true;
while (rowIterator.hasNext()) {
if (headerRow == false) {
String Rows = util.loadfile("config/ConfigValue.properties","NoOfRowsToSkip");
int i = Integer.parseInt(Rows);
HSSFRow hssfRow = (HSSFRow) rowIterator.next();
if(hssfRow.getRowNum()==0||hssfRow.getRowNum()<=i){
continue; //just skip the rows if row number is 0 TO i
}
Iterator<Cell> iterator = hssfRow.cellIterator();
List cellTempList = new ArrayList();
while (iterator.hasNext()) {
HSSFCell hssfCell = (HSSFCell) iterator.next();
if(hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC)
{DecimalFormat df = new DecimalFormat("#");
String cellValue=df.format(hssfCell.getNumericCellValue());
cellTempList.add(cellValue.toString());
}
else if(hssfCell.getCellType() == hssfCell.CELL_TYPE_STRING)
{
cellTempList.add(hssfCell.toString());
}
}
cellDataList.add(cellTempList);
} else {
headerRow = false;
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Other Exception : " + e.getStackTrace());
}
System.out.println(cellDataList);
return cellDataList;
}
}
output : [[85366667777, PLATINUM], [85367890000, GOLD], [85362524232, SILVER], [SILVER], [85362522436, DIAMOND]]
Why it is not printing [null,Silver]
or [0,SILVER]
when there is no value in its corresponding cell ?