如何摆脱空值异常

时间:2018-11-30 12:56:50

标签: java apache-poi

我想对行的单元格中的所有值求和并将汇总值写在表的底部。 我使用这段代码

<text contenteditable="true" id="Username" class="cls-7" transform="translate(142 280)"><tspan x="0" y="0">Username</tspan></text>

代码可以正常工作,甚至可以打印Sum的值,但是之后我有了double Sum[] = new double[sheet.getRow(0).getLastCellNum()]; for (int i = 1; i < LastCellNum; i++) { Sum[i - 1] = 0; for (int j = 1; j <= LastRowNum; j++) { cell = sheet.getRow(j).getCell(i); if (cell != null) { try { Sum[i - 1] = Sum[i - 1] + cell.getNumericCellValue(); } catch (NumberFormatException | NullPointerException ex) { //Handle NumberFormat and NullPointer exceptions here } catch (Exception ex) { //Handle generic exception here} } } } System.out.println(Sum[i - 1]); 。 我文件中所有选定的单元格都为空或包含数字。

0 个答案:

没有答案