Naziru Cristian Naziru Cristian - 10 months ago 86
Apache Configuration Question

Apache POI MissingCellPolicy is not really working as described in the documentation

I'm trying to set up the Apache POI for a Data Driven automation framework in Java. However, I'm kind of stuck, after several searches at the

setCellData
method.

When I try to check if a Cell in blank, the
getCell
throws this error:


The method getCell(int, Row.MissingCellPolicy) in the type XSSFRow is
not applicable for the arguments (int, Class)


And
Row.RETURN_BLANK_AS_NULL
is not really accepted:


RETURN_BLANK_AS_NULL cannot be resolved or is not a field


Here's my code:

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);
}


It does continue afterwards, but I'm interested in the 'try' part.

Thanks a lot,
Cristian

Answer Source

Your variable Row is a XSSFRow which does not contain the enum field RETURN_BLANK_AS_NULL.

You need to import org.apache.poi.ss.usermodel.Row and then use Row.RETURN_BLANK_AS_NULL.

I suggest you to rename your variable Row to avoid any conflict.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download