Top Description Fields Constructors Methods
org.apache.poi.ss.formula

pack-priv final Class OperandClassTransformer

extends Object
Class Inheritance
Imports
org.apache.poi.ss.formula.ptg.AbstractFunctionPtg, .AttrPtg, .ControlPtg, .FuncVarPtg, .IntersectionPtg, .MemAreaPtg, .MemFuncPtg, .Ptg, .RangePtg, .UnionPtg, .ValueOperatorPtg

This class performs 'operand class' transformation. Non-base tokens are classified into three operand classes:

The final operand class chosen for each token depends on the formula type and the token's place in the formula. If POI gets the operand class wrong, Excel may interpret the formula incorrectly. This condition is typically manifested as a formula cell that displays as '#VALUE!', but resolves correctly when the user presses F2, enter.

The logic implemented here was partially inspired by the description in "OpenOffice.org's Documentation of the Microsoft Excel File Format". The model presented there seems to be inconsistent with observed Excel behaviour (These differences have not been fully investigated). The implementation in this class has been heavily modified in order to satisfy concrete examples of how Excel performs the same logic (see TestRVA).

Hopefully, as additional important test cases are identified and added to the test suite, patterns might become more obvious in this code and allow for simplification.

Field Summary

Modifier and TypeField and Description
private final FormulaType

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean
private static boolean
private void
setSimpleValueFuncClass(AbstractFunctionPtg afp, byte desiredOperandClass, boolean callerForceArrayFlag)

private byte
transformClass(byte currentOperandClass, byte desiredOperandClass, boolean callerForceArrayFlag)

public void
transformFormula(ParseNode rootNode)

Traverses the supplied formula parse tree, calling Ptg.setClass() for each non-base token to set its operand class.

private void
transformFunctionNode(AbstractFunctionPtg afp, ParseNode[] children, byte desiredOperandClass, boolean callerForceArrayFlag)

private void
transformNode(ParseNode node, byte desiredOperandClass, boolean
true if one of the current node's parents is a function Ptg which has been changed from default 'V' to 'A' type (due to requirements on the function return value).
callerForceArrayFlag
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_formulaTypeback to summary
private final FormulaType _formulaType

Constructor Detail

OperandClassTransformerback to summary
public OperandClassTransformer(FormulaType formulaType)

Method Detail

isSimpleValueFunctionback to summary
private static boolean isSimpleValueFunction(Ptg token)
isSingleArgSumback to summary
private static boolean isSingleArgSum(Ptg token)
setSimpleValueFuncClassback to summary
private void setSimpleValueFuncClass(AbstractFunctionPtg afp, byte desiredOperandClass, boolean callerForceArrayFlag)
transformClassback to summary
private byte transformClass(byte currentOperandClass, byte desiredOperandClass, boolean callerForceArrayFlag)
transformFormulaback to summary
public void transformFormula(ParseNode rootNode)

Traverses the supplied formula parse tree, calling Ptg.setClass() for each non-base token to set its operand class.

transformFunctionNodeback to summary
private void transformFunctionNode(AbstractFunctionPtg afp, ParseNode[] children, byte desiredOperandClass, boolean callerForceArrayFlag)
transformNodeback to summary
private void transformNode(ParseNode node, byte desiredOperandClass, boolean callerForceArrayFlag)
Parameters
callerForceArrayFlag:boolean

true if one of the current node's parents is a function Ptg which has been changed from default 'V' to 'A' type (due to requirements on the function return value).