You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Amir Riaz <am...@gmail.com> on 2010/01/09 13:00:48 UTC

not able to calculate the formulas properly

I have the following code to evaluate the formula

switch (cell.getCellType())
        {
            case Cell.CELL_TYPE_FORMULA:
            {
                try
                {
                    CellValue cval = this.evaluator.evaluate(cell);
                    switch (cval.getCellType())
                    {
                        case Cell.CELL_TYPE_NUMERIC:
                        {
                            if (DateUtil.isCellDateFormatted(cell))
                            {

rowData.append(dateFormat.format(cval.getNumberValue()));
                                hasData = true;
                            }
                            else
                            {

rowData.append(numberFormat.format(cval.getNumberValue()));
                                hasData = true;
                            }
                            break;
                        }
                        case Cell.CELL_TYPE_STRING:
                        {

rowData.append(cval.getStringValue().trim().replaceAll("\n", ""));
                            hasData = true;
                            break;
                        }
                        case Cell.CELL_TYPE_BOOLEAN:
                        {
                            rowData.append(cval.getBooleanValue());
                            hasData = true;
                            break;
                        }
                        case Cell.CELL_TYPE_ERROR:
                        {
                            int eval=cval.getErrorValue();
                            if (eval==DIVIDE_BY_ZERO)
                            rowData.append("0");
                            hasData = true;
                            break;
                        }
                        case Cell.CELL_TYPE_BLANK:
                        {
                            rowData.append("");
                            hasData = true;
                            break;
                        }
                    }
                }

after conversion two sheet correct values but the third sheet contain
complex formula and values are not calculate correctly