use of org.apache.poi.ss.formula.ptg.OperandPtg in project poi by apache.
the class InternalWorkbook method cloneFilter.
public NameRecord cloneFilter(int filterDbNameIndex, int newSheetIndex) {
NameRecord origNameRecord = getNameRecord(filterDbNameIndex);
// copy original formula but adjust 3D refs to the new external sheet index
int newExtSheetIx = checkExternSheet(newSheetIndex);
Ptg[] ptgs = origNameRecord.getNameDefinition();
for (int i = 0; i < ptgs.length; i++) {
Ptg ptg = ptgs[i];
if (ptg instanceof Area3DPtg) {
Area3DPtg a3p = (Area3DPtg) ((OperandPtg) ptg).copy();
a3p.setExternSheetIndex(newExtSheetIx);
ptgs[i] = a3p;
} else if (ptg instanceof Ref3DPtg) {
Ref3DPtg r3p = (Ref3DPtg) ((OperandPtg) ptg).copy();
r3p.setExternSheetIndex(newExtSheetIx);
ptgs[i] = r3p;
}
}
NameRecord newNameRecord = createBuiltInName(NameRecord.BUILTIN_FILTER_DB, newSheetIndex + 1);
newNameRecord.setNameDefinition(ptgs);
newNameRecord.setHidden(true);
return newNameRecord;
}
use of org.apache.poi.ss.formula.ptg.OperandPtg in project poi by apache.
the class FormulaParser method isValidRangeOperand.
/**
* @return <code>false</code> if sub-expression represented the specified ParseNode definitely
* cannot appear on either side of the range (':') operator
*/
private static boolean isValidRangeOperand(ParseNode a) {
Ptg tkn = a.getToken();
// Note - order is important for these instance-of checks
if (tkn instanceof OperandPtg) {
// notably cell refs and area refs
return true;
}
// next 2 are special cases of OperationPtg
if (tkn instanceof AbstractFunctionPtg) {
AbstractFunctionPtg afp = (AbstractFunctionPtg) tkn;
byte returnClass = afp.getDefaultOperandClass();
return Ptg.CLASS_REF == returnClass;
}
if (tkn instanceof ValueOperatorPtg) {
return false;
}
if (tkn instanceof OperationPtg) {
return true;
}
// one special case of ControlPtg
if (tkn instanceof ParenthesisPtg) {
// parenthesis Ptg should have only one child
return isValidRangeOperand(a.getChildren()[0]);
}
// one special case of ScalarConstantPtg
if (tkn == ErrPtg.REF_INVALID) {
return true;
}
// All other ControlPtgs and ScalarConstantPtgs cannot be used with ':'
return false;
}
Aggregations