我的Excel工作表中有以下數據使用Apache POI
1234556 gold
1234456 silver
null null
4455455 platinum
我將如何讀取使用缺少cellpolicies這整個空行讀取數據之間的空行?我嘗試使用缺少cellpolicy編碼,但無法獲得所需的輸出。
for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
List cellTempList = new ArrayList();
Row r = hssfSheet.getRow(rowNum);
int lastColumn = Math.max(r.getLastCellNum(), 2);
if(r.getRowNum()==0||r.getRowNum()<=i){
continue; //just skip the rows if row number is 0 or 1
}
for (int cn = 0; cn < lastColumn; cn++) {
Row row = hssfSheet.getRow(rowNum);
Cell cell = row.getCell(cn, Row.CREATE_NULL_AS_BLANK);
// Cell cell = row.getCell(cn, Row.RETURN_NULL_AND_BLANK);
//if(row.getCell(cn)==null){
//cellTempList.add("Null");
if(cell.getCellType()==cell.CELL_TYPE_NUMERIC && cell.getColumnIndex()==0)
{//call phone number validation method
DecimalFormat df = new DecimalFormat("#");
String cellValue=df.format(cell.getNumericCellValue());
cellTempList.add(cellValue.toString());
logger.debug("Adding cell having string to "+cellTempList);
}
else if(cell.getCellType()==Cell.CELL_TYPE_STRING)
{//call string validation method
cellTempList.add(cell.toString());
logger.debug("Adding cell having string to "+cellTempList);
}
else{cellTempList.add(cell.toString()+"-");
//errorList.add(cell.getErrorCellValue());
errorList.add(cell.getRowIndex() + "$" + cell.getColumnIndex()+ "$" );
System.out.println(errorList);
}
}cellDataList.add(cellTempList);
}
} System.out.println(cellDataList);
使用此代碼其打印只有2行上面的空行留下第四行打印..?幫我
如你提到的那樣,你是否將空值填入excel文件的單元格中? – CycDemo
沒有它只是表示行是空白的 – akash