当单元格包含空值时,从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()); } 

你能帮我如何处理空值的细胞?

只需使用StringUtils.isEmpty()检查单元格是否为空/黑色。

例如, StringUtils.isEmpty(cellD.getStringCellValue()) 。 如果单元格为空或为空,这将返回true