Bug 58877

Summary: Cannot get a numeric value from a error formula cell
Product: POI Reporter: Harisingh Rajput <harisingh.rajput>
Component: HSSFAssignee: POI Developers List <dev>
Severity: major    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Harisingh Rajput 2016-01-16 13:44:57 UTC
try {
                if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
                    FormulaEvaluator fe = workbook.getCreationHelper().createFormulaEvaluator();
                    String formatCellValue = formatter.formatCellValue(cell, fe);
                    System.out.println("FE : " + formatCellValue);
            } catch (NotImplementedException et) {
                System.err.println("ERR : " + et.getMessage());
//                String j_username = formatter.formatCellValue(cell);
//                System.out.println(j_username);

From above code, I could get RSQ function cell(formula cell) value by cell.getNumericCellValue() but after writing it by output stream, I could not get cell value from output file.
Comment 1 Nick Burch 2016-01-17 08:14:21 UTC
For formula cells, you need to check the cached formula result type, and fetch the cell's value based on that - https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Cell.html#getCachedFormulaResultType%28%29 . You cannot blindly fetch the numeric value for formula cells, as many formulas don't resolve to numbers, eg they give a String or an Error (as in your case)