【发布时间】:2018-04-14 17:31:29
【问题描述】:
我正在尝试为 Java 中的数据驱动自动化框架设置 Apache POI。但是,在使用 setCellData 方法进行了几次搜索之后,我有点卡住了。
当我尝试检查单元格是否为空白时,getCell 会抛出此错误:
The method getCell(int, Row.MissingCellPolicy) in the type XSSFRow is
not applicable for the arguments (int, Class<Row>)
而Row.RETURN_BLANK_AS_NULL 并没有真正被接受:
RETURN_BLANK_AS_NULL cannot be resolved or is not a field
这是我的代码:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelUtils {
private static XSSFSheet ExcelWSheet;
private static XSSFWorkbook ExcelWBook;
private static XSSFCell Cell;
private static XSSFRow Row;
public static void setCellData(String Result, int RowNum, int ColNum) throws Exception {
try {
Row = ExcelWSheet.getRow(RowNum);
Cell = Row.getCell(ColNum, Row.RETURN_BLANK_AS_NULL);
if (Cell == null) {
Cell = Row.createCell(ColNum);
Cell.setCellValue(Result);
} else {
Cell.setCellValue(Result);
}
之后确实会继续,但我对“尝试”部分感兴趣。
非常感谢, 克里斯蒂安
【问题讨论】:
标签: java excel apache automation apache-poi