0

I am using Apache POI to read data from Excel files. I have some blank/null cells in my Excel which I want to handle using MissingCellPolicy.RETURN_NULL_AND_BLANK. However, Eclipse underlines RETURN_NULL_AND_BLANK when I hover the mouse over it and I get a pop-up saying RETURN_NULL_AND_BLANK cannot be resolved or is not a field

I have imported the Row.MissingCellPolicy class. Can anyone point out what needs to be done?

4

3 回答 3

3

MissingCellPolicyRow接口的静态嵌套类。而RETURN_NULL_AND_BLANK是ROW接口的静态字段。

所以你应该访问:

Row.RETURN_NULL_AND_BLANK;

或者改用静态导入

import static org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import static org.apache.poi.ss.usermodel.Row.RETURN_NULL_AND_BLANK;

//....
MissingCellPolicy policy = RETURN_NULL_AND_BLANK;
于 2013-02-20T11:03:25.420 回答
0

添加 Row.RETURN_NULL_AND_BLANK; 帮助我而不是添加 Row.MissingCellPolicy.RETURN_NULL_AND_BLANK; 或 MissingCellPolicy.RETURN_NULL_AND_BLANK;并且 Eclipse 不会抛出错误。

这是因为我的工作表是 XSSFSheet,它只返回一个 XSSFRow 行,而 XSSFRow(或者甚至是 HSSFRow)直接从 Row 类继承这些常量。在此处查看更多信息

于 2013-02-22T00:26:06.833 回答
0
Row is interface 
MissingCellPolicy is the enum in Row
and
1. RETURN_NULL_AND_BLANK
2. RETURN_BLANK_AS_NULL
3. CREATE_NULL_AS_BLANK

是要访问 1 到 3 中的任何一个的静态字段

利用

Row.MissingCellPolicy.RETURN_NULL_AND_BLANK

或根据要求使用其他两个

于 2017-12-03T20:44:50.313 回答