0
셀이 발견되면 데이터를 Excel 파일로 저장하는 코드가 있습니다. 그러나 내가 아래 코드를 입력하면 오류가 발생합니다. :Apache POI 오류 메시지가 RETURN_BLANK_AS_NULL에 대해 표시됩니다.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
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;
import org.apache.poi.ss.usermodel.Row;
import Config.Constants;
public class ExcelUtils {
private static XSSFSheet ExcelWSheet;
private static XSSFWorkbook ExcelWBook;
private static XSSFCell Cell;
private static XSSFRow Row, xRow;
public static void setExcelFile(String Path, String SheetName) throws Exception {
// TODO Auto-generated method stub
FileInputStream ExcelFile = new FileInputStream(Path);
ExcelWBook = new XSSFWorkbook(ExcelFile);
// ExcelWSheet = ExcelWBook.getSheet(SheetName);
}
public static String getCellData(int RowNum, int ColNum, String SheetName) throws Exception {
ExcelWSheet = ExcelWBook.getSheet(SheetName);
try {
Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
String CellData = Cell.getStringCellValue();
return CellData;
} catch (Exception e) {
return "";
}
}
public static int getRowCount(String SheetName) {
ExcelWSheet = ExcelWBook.getSheet(SheetName);
int number = ExcelWSheet.getLastRowNum() + 1;
return number;
}
//This method is to get the Row number of the test case
//This methods takes three arguments(Test Case name , Column Number & Sheet name)
public static int getRowContains(String sTestCaseName, int colNum, String SheetName) throws Exception {
int i;
ExcelWSheet = ExcelWBook.getSheet(SheetName);
int rowCount = ExcelUtils.getRowCount(SheetName);
for (i = 0; i < rowCount; i++) {
if (ExcelUtils.getCellData(i, colNum, SheetName).equalsIgnoreCase(sTestCaseName)) {
break;
}
}
return i;
}
//This method is to get the count of the test steps of test case
//This method takes three arguments (Sheet name, Test Case Id & Test case row number)
public static int getTestStepsCount(String SheetName, String sTestCaseID, int iTestCaseStart) throws Exception {
for (int i = iTestCaseStart; i <= ExcelUtils.getRowCount(SheetName); i++) {
if (!sTestCaseID.equals(ExcelUtils.getCellData(i, Constants.Col_TestCaseID, SheetName))) {
int number = i;
return number;
}
}
ExcelWSheet = ExcelWBook.getSheet(SheetName);
int number = ExcelWSheet.getLastRowNum() + 1;
return number;
}
@SuppressWarnings("static-access")
public static void setCellData(String Result, int RowNum, int ColNum, String SheetName) throws Exception {
try {
ExcelWSheet = ExcelWBook.getSheet(SheetName);
Row = ExcelWSheet.getRow(RowNum);
xRow = ExcelWSheet.getRow(RowNum);
// Row.RETURN_BLANK_AS_NULL;
// ExcelWBook.setMissingCellPolicy(Row.RETURN_BLANK_AS_NULL);
//Cell = Row.getCell(ColNum, Blank);
Cell = xRow.getCell(ColNum, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
if (Cell == null) {
Cell = Row.createCell(ColNum);
Cell.setCellValue(Result);
} else {
Cell.setCellValue(Result);
}
// Constant variables Test Data path and Test Data file name
FileOutputStream fileOut = new FileOutputStream(Constants.Path_TestData);
//ExcelWBook.write(fileOut);
ExcelWBook.write(fileOut);
//fileOut.flush();
fileOut.close();
ExcelWBook = new XSSFWorkbook(new FileInputStream(Constants.Path_TestData));
} catch (Exception e) {
DriverScript.bResult = false;
}
}
}
오류 메시지 :
MissingCellPolicy를 해결할 수없는 또는 내가 사용할 때 반면 필드
없는 수 "Row.RETURN_BLANK_AS_NULL
는"이 방법은 사용되지 않습니다 말한다. 이 두 문제에 대한 코드를 성공적으로 실행하기위한 몇 가지 해결책이 있습니까?