How to get the numeric value from excel in selenium

Hi ,

Below is my code:

double d = wb.getSheetAt(0).getRow(1).getCell(6).getNumericCellValue();
String s1 = String.valueOf(d);
System.out.println(s1);

I have given a value of 66777878787867800 in the excel sheet.When i am executing the above code,output is coming as 6.67778787878678E16. And when i tried

double d = wb.getSheetAt(0).getRow(1).getCell(6).getNumericCellValue();
String s1 = String.valueOf(d);
System.out.println(s1);
//s1=(int)Double.parseDouble(s1)+””;
//System.out.println(s1);
Output is coming as 2147483647.

Can any one please tell me how to get the exact numeric value from excel and use that in my application. My email id is ramgd001@gmail.com.

Thanks in Advance
Ram

Default Asked on May 18, 2016 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Hi Ram,

    Can you try this piece of code?

    InputStream inp =getClass().getResourceAsStream(“filename.xls”));
    Workbook wb = WorkbookFactory.create(inp);
    DataFormatter objDefaultFormat = new DataFormatter();
    FormulaEvaluator objFormulaEvaluator = new HSSFFormulaEvaluator((HSSFWorkbook) wb);

    Sheet sheet= wb.getSheetAt(0);
    Iterator<Row> objIterator = sheet.rowIterator();

    while(objIterator.hasNext()){

    Row row = objIterator.next();
    Cell cellValue = row.getCell(0);
    objFormulaEvaluator.evaluate(cellValue); // This will evaluate the cell, And any type of cell will return string value
    String cellValueStr = objDefaultFormat.formatCellValue(cellValue,objFormulaEvaluator);

    Doctor Answered on May 25, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.