HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellFormula("1+IF(1,,)");
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv;
try {
cv = fe.evaluate(cell);
} catch (RuntimeException e) {
throw new AssertionFailedError("Missing arg result not being handled correctly.");
}
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
// adding blank to 1.0 gives 1.0
assertEquals(1.0, cv.getNumberValue(), 0.0);
// check with string operand
cell.setCellFormula("\"abc\"&IF(1,,)");
fe.notifySetFormula(cell);
cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType());
// adding blank to "abc" gives "abc"
assertEquals("abc", cv.getStringValue());
// check CHOOSE()
cell.setCellFormula("\"abc\"&CHOOSE(2,5,,9)");
fe.notifySetFormula(cell);
cv = fe.evaluate(cell);
assertEquals(HSSFCell.CELL_TYPE_STRING, cv.getCellType());
// adding blank to "abc" gives "abc"
assertEquals("abc", cv.getStringValue());
}