Example usage for org.apache.poi.xssf.usermodel XSSFFormulaEvaluator evaluate

List of usage examples for org.apache.poi.xssf.usermodel XSSFFormulaEvaluator evaluate

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFFormulaEvaluator evaluate.

Prototype

@Override
public CellValue evaluate(Cell cell) 

Source Link

Document

If cell contains a formula, the formula is evaluated and returned, else the CellValue simply copies the appropriate cell value from the cell and also its cell type.

Usage

From source file:org.tridas.io.formats.ooxml.OOXMLReader.java

License:Apache License

private Double getCellValueAsDouble(Cell cell) {

    if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
        return null;
    } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
        return null;
    } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
        return null;
    } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
        try {//from w w w.j  av  a2s .c om
            XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator((XSSFWorkbook) wb);
            return evaluator.evaluate(cell).getNumberValue();
        } catch (Exception e) {
            return null;
        }
    } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
        return cell.getNumericCellValue();
    } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
        try {
            Double dbl = Double.valueOf(cell.getStringCellValue());
            return dbl;
        } catch (NumberFormatException e) {
            return null;
        }
    }

    return null;

}