use of org.apache.poi.ss.formula.ptg.UnionPtg in project poi by apache.
the class TestAreaReference method testDiscontinousReference.
public void testDiscontinousReference() throws Exception {
InputStream is = HSSFTestDataSamples.openSampleFileStream("44167.xls");
HSSFWorkbook wb = new HSSFWorkbook(is);
InternalWorkbook workbook = TestHSSFWorkbook.getInternalWorkbook(wb);
HSSFEvaluationWorkbook eb = HSSFEvaluationWorkbook.create(wb);
assertEquals(1, wb.getNumberOfNames());
String sheetName = "Tabelle1";
String rawRefA = "$C$10:$C$14";
String rawRefB = "$C$16:$C$18";
String refA = sheetName + "!" + rawRefA;
String refB = sheetName + "!" + rawRefB;
String ref = refA + "," + refB;
// Check the low level record
NameRecord nr = workbook.getNameRecord(0);
assertNotNull(nr);
assertEquals("test", nr.getNameText());
Ptg[] def = nr.getNameDefinition();
assertEquals(4, def.length);
MemFuncPtg ptgA = (MemFuncPtg) def[0];
Area3DPtg ptgB = (Area3DPtg) def[1];
Area3DPtg ptgC = (Area3DPtg) def[2];
UnionPtg ptgD = (UnionPtg) def[3];
assertEquals("", ptgA.toFormulaString());
assertEquals(refA, ptgB.toFormulaString(eb));
assertEquals(refB, ptgC.toFormulaString(eb));
assertEquals(",", ptgD.toFormulaString());
assertEquals(ref, HSSFFormulaParser.toFormulaString(wb, nr.getNameDefinition()));
// Check the high level definition
int idx = wb.getNameIndex("test");
assertEquals(0, idx);
HSSFName aNamedCell = wb.getNameAt(idx);
// Should have 2 references
assertEquals(ref, aNamedCell.getRefersToFormula());
// Check the parsing of the reference into cells
assertFalse(AreaReference.isContiguous(aNamedCell.getRefersToFormula()));
AreaReference[] arefs = AreaReference.generateContiguous(aNamedCell.getRefersToFormula());
assertEquals(2, arefs.length);
assertEquals(refA, arefs[0].formatAsString());
assertEquals(refB, arefs[1].formatAsString());
for (AreaReference ar : arefs) {
confirmResolveCellRef(wb, ar.getFirstCell());
confirmResolveCellRef(wb, ar.getLastCell());
}
}
use of org.apache.poi.ss.formula.ptg.UnionPtg in project poi by apache.
the class OperandClassTransformer method transformNode.
/**
* @param callerForceArrayFlag <code>true</code> 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).
*/
private void transformNode(ParseNode node, byte desiredOperandClass, boolean callerForceArrayFlag) {
Ptg token = node.getToken();
ParseNode[] children = node.getChildren();
boolean isSimpleValueFunc = isSimpleValueFunction(token);
if (isSimpleValueFunc) {
boolean localForceArray = desiredOperandClass == Ptg.CLASS_ARRAY;
for (int i = 0; i < children.length; i++) {
transformNode(children[i], desiredOperandClass, localForceArray);
}
setSimpleValueFuncClass((AbstractFunctionPtg) token, desiredOperandClass, callerForceArrayFlag);
return;
}
if (isSingleArgSum(token)) {
// Need to process the argument of SUM with transformFunctionNode below
// so make a dummy FuncVarPtg for that call.
token = FuncVarPtg.SUM;
// Note - the tAttrSum token (node.getToken()) is a base
// token so does not need to have its operand class set
}
if (token instanceof ValueOperatorPtg || token instanceof ControlPtg || token instanceof MemFuncPtg || token instanceof MemAreaPtg || token instanceof UnionPtg || token instanceof IntersectionPtg) {
// Value Operator Ptgs and Control are base tokens, so token will be unchanged
// but any child nodes are processed according to desiredOperandClass and callerForceArrayFlag
// As per OOO documentation Sec 3.2.4 "Token Class Transformation", "Step 1"
// All direct operands of value operators that are initially 'R' type will
// be converted to 'V' type.
byte localDesiredOperandClass = desiredOperandClass == Ptg.CLASS_REF ? Ptg.CLASS_VALUE : desiredOperandClass;
for (int i = 0; i < children.length; i++) {
transformNode(children[i], localDesiredOperandClass, callerForceArrayFlag);
}
return;
}
if (token instanceof AbstractFunctionPtg) {
transformFunctionNode((AbstractFunctionPtg) token, children, desiredOperandClass, callerForceArrayFlag);
return;
}
if (children.length > 0) {
if (token == RangePtg.instance) {
// TODO is any token transformation required under the various ref operators?
return;
}
throw new IllegalStateException("Node should not have any children");
}
if (token.isBaseToken()) {
// nothing to do
return;
}
token.setClass(transformClass(token.getPtgClass(), desiredOperandClass, callerForceArrayFlag));
}
Aggregations