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;
}
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;
}
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() + ")");
}
Aggregations