2
我从Excel中获取数据,我需要对某些单元格包含空值的行进行计数。代码没有任何返回。对于这个单元格中包含一些值的行,它正常工作。你能帮我如何处理空值的单元格吗?当单元格包含空值时从Excel中获取数据
的代码如下:
HSSFSheet sheet = workbook.getSheetAt(1);
// Get iterator to all the rows in current sheet
Iterator<Row> rowIterator = sheet.iterator();
// Iterate through rows
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
// Index of column D is 3 (A->0, B->1, etc)
Cell cellD = row.getCell(3);
Cell cellG = row.getCell(6);
//
String key = null;
Integer value = null;
// finding cell type
int cellTypeG = cellG.getCellType();
// getting value from first cell
key = cellD.getStringCellValue();
// fetching value to the Double, to be able to compare data
if (Cell.CELL_TYPE_NUMERIC == cellTypeG) {
value = new Double(cellG.getNumericCellValue()).intValue();
if (value != null) {
if (map.containsKey(key)) {
map.put(key, map.get(key) + 1);
} else {
map.put(key, 1);
}
}
}
}
// cycle which is filling the map
for (Entry<String, Integer> e : map.entrySet()) {
System.out.println(e.getKey() + ": " + e.getValue());
}
我知道现在阅读这些文档是非常流行的,但是会发生什么[如果你给它一个尝试?](http://poi.apache.org/spreadsheet/quick-guide.html#Iterator)只有[非常清楚和易于遵循遍历行和单元格的文档,包括空白/空处理](http://poi.apache.org/spreadsheet/quick-guide.html#Iterator)..... – Gagravarr