Class OperationEvaluationContext

java.lang.Object
org.apache.poi.ss.formula.OperationEvaluationContext

public class OperationEvaluationContext extends Object
Contains all the contextual information required to evaluate an operation within a formula

For POI internal use only. Not final so that an evaluator can subclass it to customise how references are resolved before passing it to WorkbookEvaluator.evaluateFormula(OperationEvaluationContext, Ptg[]).

  • Field Details

  • Constructor Details

    • OperationEvaluationContext

      public OperationEvaluationContext(WorkbookEvaluator bookEvaluator, EvaluationWorkbook workbook, int sheetIndex, int srcRowNum, int srcColNum)
      Creates a context for evaluating formula tokens at the given position, using the evaluation tracker of the given WorkbookEvaluator.

      This constructor is intended for code outside this package - e.g. custom EvaluationWorkbook implementations or FreeRefFunction callers - that needs a context but has no access to the internal evaluation tracker.

      Parameters:
      bookEvaluator - the evaluator of the workbook the formula belongs to
      workbook - the workbook the formula belongs to
      sheetIndex - the index of the sheet the formula is evaluated on
      srcRowNum - the row index of the formula's position (base for relative references)
      srcColNum - the column index of the formula's position (base for relative references)
      Since:
      6.0.0
    • OperationEvaluationContext

      public OperationEvaluationContext(WorkbookEvaluator bookEvaluator, EvaluationWorkbook workbook, int sheetIndex, int srcRowNum, int srcColNum, org.apache.poi.ss.formula.EvaluationTracker tracker)
    • OperationEvaluationContext

      public OperationEvaluationContext(WorkbookEvaluator bookEvaluator, EvaluationWorkbook workbook, int sheetIndex, int srcRowNum, int srcColNum, org.apache.poi.ss.formula.EvaluationTracker tracker, boolean isSingleValue)
  • Method Details

    • isArraymode

      public boolean isArraymode()
    • setArrayMode

      public void setArrayMode(boolean value)
    • getWorkbook

      public EvaluationWorkbook getWorkbook()
    • getRowIndex

      public int getRowIndex()
    • getColumnIndex

      public int getColumnIndex()
    • getRefEvaluatorForCurrentSheet

      public org.apache.poi.ss.formula.SheetRangeEvaluator getRefEvaluatorForCurrentSheet()
    • getDynamicReference

      public ValueEval getDynamicReference(String workbookName, String sheetName, String refStrPart1, String refStrPart2, boolean isA1Style)
      Resolves a cell or area reference dynamically.
      Parameters:
      workbookName - the name of the workbook containing the reference. If null the current workbook is assumed. Note - to evaluate formulas which use multiple workbooks, a CollaboratingWorkbooksEnvironment must be set up.
      sheetName - the name of the sheet containing the reference. May be null (when workbookName is also null) in which case the current workbook and sheet is assumed.
      refStrPart1 - the single cell reference or first part of the area reference. Must not be null.
      refStrPart2 - the second part of the area reference. For single cell references this parameter must be null
      isA1Style - specifies the format for refStrPart1 and refStrPart2. Pass true for 'A1' style and false for 'R1C1' style.
      Returns:
      a RefEval or AreaEval
      Throws:
      IllegalStateException - If invalid parameters are provided
    • findUserDefinedFunction

      public FreeRefFunction findUserDefinedFunction(String functionName)
    • getRefEval

      public ValueEval getRefEval(int rowIndex, int columnIndex)
    • getRef3DEval

      public ValueEval getRef3DEval(Ref3DPtg rptg)
    • getRef3DEval

      public ValueEval getRef3DEval(Ref3DPxg rptg)
    • getAreaEval

      public ValueEval getAreaEval(int firstRowIndex, int firstColumnIndex, int lastRowIndex, int lastColumnIndex)
    • getArea3DEval

      public ValueEval getArea3DEval(Area3DPtg aptg)
    • getArea3DEval

      public ValueEval getArea3DEval(Area3DPxg aptg)
    • getAreaValueEval

      public ValueEval getAreaValueEval(int firstRowIndex, int firstColumnIndex, int lastRowIndex, int lastColumnIndex, Object[][] tokens)
    • getNameXEval

      public ValueEval getNameXEval(NameXPtg nameXPtg)
    • getNameXEval

      public ValueEval getNameXEval(NameXPxg nameXPxg)
    • getSheetIndex

      public int getSheetIndex()
    • isSingleValue

      public boolean isSingleValue()
      default true
      Returns:
      flag indicating whether evaluation should "unwrap" the result to a single value based on the context row/column
    • applyR1C1Reference

      public static CellReference applyR1C1Reference(CellReference anchorReference, String relativeReference)