Apache POI - Reading excel data row by row
Program to read Excel data & store it in Array List - Each row as an object containing column data in the form of Strings
//Function to read Excel Data - Row by Row
public void getTest() throws CustomException {
// array list to read each row's data as one record - i.e each test steps is stored as one record
ArrayList<Object> excelData = new ArrayList<>();
//store each row data as an object
XSSFSheet sheet = getExcelReader().getSheet("Functions");
for (Row row : sheet) {
// each column data in the row[Test step] is read to list
List<String> data = null;
data = new ArrayList<>();
for (Cell cell : row) {
data.add(cell.getStringCellValue()); //each column value in the row is read one after the other & copied to array list
}
//once complete row data - all the columns are copied to an array list
// Now this list is treated as a list object & added to one more array list
excelData.add(data);
}
System.out.println(excelData);
}
public static void main(String... args) throws CustomException {
//get an object of the class
reader = getExcelReader();
reader.getWorkBook("E:\\TestAutomation\\UpdatedTestInput.xlsx");
reader.getTest();
Input excel sheet Data:
Output post execution:
Comments
Post a Comment