Bug 58877 - Cannot get a numeric value from a error formula cell
Summary: Cannot get a numeric value from a error formula cell
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2016-01-16 13:44 UTC by Harisingh Rajput
Modified: 2016-01-17 08:14 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
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)