I am trying to get input from excel for my testcase . My input contains both string and numeric values. I know how to retrieve value for single datatype using the below code
public Object[][] readnumericvalue() throws IOException {
File src = new File("filepath");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(1);
XSSFRow row = sheet1.getRow(0);
int rowcount = sheet1.getLastRowNum();
int columnCount = row.getLastCellNum();
Object data1[][]=new Double[rowcount+1][columnCount];
columnCount = columnCount-1;
for(int i=0;i<=rowcount;i++) {
for(int j=0;j<=columnCount;j++) {
data1[i[j]= sheet1.getRow(i).getCell(j).getNumericCellValue();
}
}
return data1;
}
I tried to read both the datatypes in single dataprovider but I don't know how to initialize 2D-array for multiple datatypes
File src = new File("");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(0);
XSSFRow row = sheet1.getRow(0);
int rowcount = sheet1.getLastRowNum();
int columnCount = row.getLastCellNum();
Object data1[][]=new String[rowcount+1][columnCount];
columnCount = columnCount-1
for(int i=0;i<=rowcount;i++) {
for(int j=0;j<=columnCount;j++) {
Cell cell = row.getCell(j);
switch (cell.getCellTypeEnum()) {
case STRING:
data1[i][j]=sheet1.getRow(i).getCell(j).getStringCellValue();
break;
case NUMERIC:
data1[i][j]=sheet1.getRow(i).getCell(j).getNumericCellValue();
break;
}
}
}
return data1;