Search in sources :

Example 1 with EvaluationCell

use of org.apache.poi.ss.formula.EvaluationCell in project poi by apache.

the class ForkedEvaluationSheet method getOrCreateUpdatableCell.

public ForkedEvaluationCell getOrCreateUpdatableCell(int rowIndex, int columnIndex) {
    RowColKey key = new RowColKey(rowIndex, columnIndex);
    ForkedEvaluationCell result = _sharedCellsByRowCol.get(key);
    if (result == null) {
        EvaluationCell mcell = _masterSheet.getCell(rowIndex, columnIndex);
        if (mcell == null) {
            CellReference cr = new CellReference(rowIndex, columnIndex);
            throw new UnsupportedOperationException("Underlying cell '" + cr.formatAsString() + "' is missing in master sheet.");
        }
        result = new ForkedEvaluationCell(this, mcell);
        _sharedCellsByRowCol.put(key, result);
    }
    return result;
}
Also used : EvaluationCell(org.apache.poi.ss.formula.EvaluationCell) CellReference(org.apache.poi.ss.util.CellReference)

Example 2 with EvaluationCell

use of org.apache.poi.ss.formula.EvaluationCell in project poi by apache.

the class XSSFEvaluationSheet method getCell.

@Override
public EvaluationCell getCell(int rowIndex, int columnIndex) {
    // cache for performance: ~30% speedup due to caching
    if (_cellCache == null) {
        _cellCache = new HashMap<CellKey, EvaluationCell>(_xs.getLastRowNum() * 3);
        for (final Row row : _xs) {
            final int rowNum = row.getRowNum();
            for (final Cell cell : row) {
                // cast is safe, the iterator is just defined using the interface
                final CellKey key = new CellKey(rowNum, cell.getColumnIndex());
                final EvaluationCell evalcell = new XSSFEvaluationCell((XSSFCell) cell, this);
                _cellCache.put(key, evalcell);
            }
        }
    }
    final CellKey key = new CellKey(rowIndex, columnIndex);
    EvaluationCell evalcell = _cellCache.get(key);
    // See bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss
    if (evalcell == null) {
        XSSFRow row = _xs.getRow(rowIndex);
        if (row == null) {
            return null;
        }
        XSSFCell cell = row.getCell(columnIndex);
        if (cell == null) {
            return null;
        }
        evalcell = new XSSFEvaluationCell(cell, this);
        _cellCache.put(key, evalcell);
    }
    return evalcell;
}
Also used : EvaluationCell(org.apache.poi.ss.formula.EvaluationCell) Row(org.apache.poi.ss.usermodel.Row) EvaluationCell(org.apache.poi.ss.formula.EvaluationCell) Cell(org.apache.poi.ss.usermodel.Cell)

Example 3 with EvaluationCell

use of org.apache.poi.ss.formula.EvaluationCell in project poi by apache.

the class BaseXSSFFormulaEvaluator method evaluateFormulaCellValue.

/**
     * Returns a CellValue wrapper around the supplied ValueEval instance.
     */
protected CellValue evaluateFormulaCellValue(Cell cell) {
    EvaluationCell evalCell = toEvaluationCell(cell);
    ValueEval eval = _bookEvaluator.evaluate(evalCell);
    if (eval instanceof NumberEval) {
        NumberEval ne = (NumberEval) eval;
        return new CellValue(ne.getNumberValue());
    }
    if (eval instanceof BoolEval) {
        BoolEval be = (BoolEval) eval;
        return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof StringEval) {
        StringEval ne = (StringEval) eval;
        return new CellValue(ne.getStringValue());
    }
    if (eval instanceof ErrorEval) {
        return CellValue.getError(((ErrorEval) eval).getErrorCode());
    }
    throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
}
Also used : BoolEval(org.apache.poi.ss.formula.eval.BoolEval) EvaluationCell(org.apache.poi.ss.formula.EvaluationCell) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) CellValue(org.apache.poi.ss.usermodel.CellValue) StringEval(org.apache.poi.ss.formula.eval.StringEval) ErrorEval(org.apache.poi.ss.formula.eval.ErrorEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Aggregations

EvaluationCell (org.apache.poi.ss.formula.EvaluationCell)3 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)1 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)1 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)1 StringEval (org.apache.poi.ss.formula.eval.StringEval)1 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellValue (org.apache.poi.ss.usermodel.CellValue)1 Row (org.apache.poi.ss.usermodel.Row)1 CellReference (org.apache.poi.ss.util.CellReference)1