HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue();
double expectedValue = cellC.getNumericCellValue();
assertEquals(
"Problem with a formula at " + new CellReference(cellA).formatAsString()
+ ": " + cellA.getCellFormula() + " :"
+ "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ",
expectedValue, actualValue, 0.0001);
}
HSSFSheet sheet2 = wb.getSheet("MSDN Example 2");
for (int rowIx=9; rowIx<=14; rowIx++) {
HSSFRow row = sheet2.getRow(rowIx-1);
HSSFCell cellA = row.getCell(0); // cell containing a formula with COUNTIF
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cellA.getCellType());
HSSFCell cellC = row.getCell(2); // cell with a reference value
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cellC.getCellType());
CellValue cv = fe.evaluate(cellA);
double actualValue = cv.getNumberValue();
double expectedValue = cellC.getNumericCellValue();
assertEquals(
"Problem with a formula at " +
new CellReference(cellA).formatAsString() + "[" + cellA.getCellFormula()+"]: "