I am downloading an excel from an application with the help of selenium. When I am trying to get one value from that excel cell, it is returning as: 0.0
while that field value is : 3,662,772
(This is a result of some formula)
Can someone point me, what I am doing wrong here?
Code:
Decimalformat decimalformat = new DecimalFormat("0.#");
FileInputStream fsIP= new FileInputStream(new File("src/test/resources/test.xlsx"));
XSSFWorkbook wb = new XSSFWorkbook(fsIP);
XSSFSheet worksheet = wb.getSheetAt(0);
Double myvalue = Double.valueOf(decimalFormat.format(sheet.getRow(1).getCell(1).getNumericCellValue()))
Output (When excel is not saved manually) : 0.0
When I manually save the excel file and try to fetch the value again from above code, it returns the correct value.
Output (When excel is saved manually) : 3662772
I tried to evaulate the formula:
CellReference cellReference = new CellReference("P212");
Row row = sheet.getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());
System.out.println("1:" + cell);
System.out.println("2: " +
cell.getCachedFormulaResultTypeEnum());
System.out.println("3:" + cell.getNumericCellValue());
evaluator.evaluateFormulaCellEnum(cell);
Output:
java.lang.RuntimeException: Invalid ValueEval type passed for conversion: (class org.apache.poi.ss.formula.eval.RefListEval)
Apache POI Version : 3.17
Update:
After reading the comments, it narrowed down that the issue is coming because :
- It is a formula value when fetched without evaluating, giving the cached value which i think is 0.0
- To get the value, I will need to evaluate the formula, which when I used, is failing.