0

我对 Jexcel 有疑问。我想读取一个 excel 文件并为每个单元格检测背景颜色。我正在这样做:

Cell cell = sheet.getCell(i, j);
Colour cellColor = cell.getCellFormat().getBackgroundColour();

我总是在 cell.getCellFormat() 处出现 NullPointerException。我检查了文件是否被正确读取,并且我还能够检索内容。我究竟做错了什么?

谢谢

4

2 回答 2

0

不,单元格已满,无论如何,谢谢。我发现了这个问题,似乎 excel 文件的格式很奇怪,jexcel 无法识别格式,而是检索一些错误或类似的东西,结果返回 null。

于 2014-07-25T12:14:42.670 回答
0

(i,j) 处的单元格为空,因此没有要获取的格式信息。在为单元格调用 getCellFormat() 方法之前,您可以测试它是否为空。如下所示:

if (cell.getContents != null) {
    cellColor = cell.getCellFormat().getBackgroundColour();
}
于 2014-07-24T12:44:14.370 回答