/** * Dereferences a single value from any AreaEval or RefEval evaluation * result. If the supplied evaluationResult is just a plain value, it is * returned as-is. * * @return a {@link NumberEval}, {@link StringEval}, {@link BoolEval}, or * {@link ErrorEval}. Never <code>null</code>. {@link BlankEval} is * converted to {@link NumberEval#ZERO} */ public static ValueEval DereferenceResult(ValueEval evaluationResult, OperationEvaluationContext ec) { ValueEval value; if (ec == null) { throw new ArgumentNullException("OperationEvaluationContext ec is null"); } if (ec.GetWorkbook() == null) { throw new ArgumentNullException("OperationEvaluationContext ec.getWorkbook() is null"); } IEvaluationSheet evalSheet = ec.GetWorkbook().GetSheet(ec.SheetIndex); IEvaluationCell evalCell = evalSheet.GetCell(ec.RowIndex, ec.ColumnIndex); if (evalCell.IsPartOfArrayFormulaGroup && evaluationResult is AreaEval) { value = OperandResolver.GetElementFromArray((AreaEval)evaluationResult, evalCell); } else { value = DereferenceResult(evaluationResult, ec.RowIndex, ec.ColumnIndex); } return(value); }