for(Workbook wb : wbs) {
Sheet s = wb.createSheet();
Row r = s.createRow(0);
// Setup
Cell cn = r.createCell(0, Cell.CELL_TYPE_NUMERIC);
cn.setCellValue(1.2);
Cell cs = r.createCell(1, Cell.CELL_TYPE_STRING);
cs.setCellValue("Testing");
Cell cfn = r.createCell(2, Cell.CELL_TYPE_FORMULA);
cfn.setCellFormula("A1");
Cell cfs = r.createCell(3, Cell.CELL_TYPE_FORMULA);
cfs.setCellFormula("B1");
FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
assertEquals(Cell.CELL_TYPE_NUMERIC, fe.evaluate(cfn).getCellType());
assertEquals(Cell.CELL_TYPE_STRING, fe.evaluate(cfs).getCellType());
fe.evaluateFormulaCell(cfn);
fe.evaluateFormulaCell(cfs);
// Now test
assertEquals(Cell.CELL_TYPE_NUMERIC, cn.getCellType());
assertEquals(Cell.CELL_TYPE_STRING, cs.getCellType());
assertEquals(Cell.CELL_TYPE_FORMULA, cfn.getCellType());
assertEquals(Cell.CELL_TYPE_NUMERIC, cfn.getCachedFormulaResultType());
assertEquals(Cell.CELL_TYPE_FORMULA, cfs.getCellType());
assertEquals(Cell.CELL_TYPE_STRING, cfs.getCachedFormulaResultType());
// Different ways of retrieving
assertEquals(1.2, cn.getNumericCellValue());
try {
cn.getRichStringCellValue();
fail();
} catch(IllegalStateException e) {}
assertEquals("Testing", cs.getStringCellValue());
try {
cs.getNumericCellValue();
fail();
} catch(IllegalStateException e) {}
assertEquals(1.2, cfn.getNumericCellValue());
try {
cfn.getRichStringCellValue();
fail();
} catch(IllegalStateException e) {}
assertEquals("Testing", cfs.getStringCellValue());
try {
cfs.getNumericCellValue();
fail();
} catch(IllegalStateException e) {}
}
}