When I am passing numeric values into excel sheet, it is taking as double so that there was DataProvider Mismatch exception. How to handle this exception and how to pass only numeric values instead of double values?
Below is my code:
@DataProvider(name = "testdata")
public Object[][] TestDataFeed() throws Exception
{
FileInputStream fis = new
FileInputStream("C:\\Users\\vidhya.r\\Desktop\\Testdata.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sh1 = wb.getSheetAt(2);
int numrow = sh1.getLastRowNum() + 1;
int colnum = sh1.getRow(0).getLastCellNum();
System.out.println("numrow ======= " + numrow);
System.out.println("colnum ======= " + colnum);
Object[][] data = new Object[numrow - 1][colnum];
System.out.println("data.length ======= " + data.length);
for (int i = 1; i < numrow; i++)
{
Row row = sh1.getRow(i);
for (int j = 1; j < row.getLastCellNum(); j++)
{
int cellValue = sh1.getRow(i).getCell(j).getCellType();
if (cellValue == Cell.CELL_TYPE_NUMERIC)
{
Object obj =
sh1.getRow(i).getCell(j).getNumericCellValue();
data[i - 1][j-1] = obj;
System.out.println("obj =num= " + obj);
}
else if (cellValue == Cell.CELL_TYPE_STRING)
{
Object obj =
sh1.getRow(i).getCell(j).getStringCellValue();
data[i - 1][j-1] = obj;
System.out.println("obj =str= " + obj);
}
}
}
return data;
}
Kindly help me to handle this
Here is a workaround to your problem...