Search in sources :

Example 6 with IntPtg

use of org.apache.poi.ss.formula.ptg.IntPtg in project poi by apache.

the class TestFormulaParserIf method testIfSingleCondition.

public void testIfSingleCondition() {
    Ptg[] ptgs = parseFormula("IF(1=1,10)");
    assertEquals(7, ptgs.length);
    assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
    AttrPtg ifFunc = (AttrPtg) ptgs[3];
    assertTrue("It is not an if", ifFunc.isOptimizedIf());
    assertTrue("Single Value is not an IntPtg", (ptgs[4] instanceof IntPtg));
    IntPtg intPtg = (IntPtg) ptgs[4];
    assertEquals("Result", (short) 10, intPtg.getValue());
    assertTrue("Ptg is not a Variable Function", (ptgs[6] instanceof FuncVarPtg));
    FuncVarPtg funcPtg = (FuncVarPtg) ptgs[6];
    assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
}
Also used : IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) LessEqualPtg(org.apache.poi.ss.formula.ptg.LessEqualPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) NotEqualPtg(org.apache.poi.ss.formula.ptg.NotEqualPtg) FuncPtg(org.apache.poi.ss.formula.ptg.FuncPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) AddPtg(org.apache.poi.ss.formula.ptg.AddPtg) MultiplyPtg(org.apache.poi.ss.formula.ptg.MultiplyPtg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) LessThanPtg(org.apache.poi.ss.formula.ptg.LessThanPtg) BoolPtg(org.apache.poi.ss.formula.ptg.BoolPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg)

Example 7 with IntPtg

use of org.apache.poi.ss.formula.ptg.IntPtg in project poi by apache.

the class TestFormulaParser method testSpaceAtStartOfFormula.

@Test
public void testSpaceAtStartOfFormula() {
    // Simulating cell formula of "= 4" (note space)
    // The same Ptg array can be observed if an excel file is saved with that exact formula
    AttrPtg spacePtg = AttrPtg.createSpace(AttrPtg.SpaceType.SPACE_BEFORE, 1);
    Ptg[] ptgs = { spacePtg, new IntPtg(4) };
    String formulaString;
    try {
        formulaString = toFormulaString(ptgs);
    } catch (IllegalStateException e) {
        if (e.getMessage().equalsIgnoreCase("too much stuff left on the stack")) {
            fail("Identified bug 44609");
        }
        // else some unexpected error
        throw e;
    }
    // FormulaParser strips spaces anyway
    assertEquals("4", formulaString);
    ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, AddPtg.instance };
    formulaString = toFormulaString(ptgs);
    assertEquals("3+4", formulaString);
}
Also used : IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) NumberPtg(org.apache.poi.ss.formula.ptg.NumberPtg) ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) PercentPtg(org.apache.poi.ss.formula.ptg.PercentPtg) RangePtg(org.apache.poi.ss.formula.ptg.RangePtg) AddPtg(org.apache.poi.ss.formula.ptg.AddPtg) EqualPtg(org.apache.poi.ss.formula.ptg.EqualPtg) UnaryMinusPtg(org.apache.poi.ss.formula.ptg.UnaryMinusPtg) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) DividePtg(org.apache.poi.ss.formula.ptg.DividePtg) GreaterThanPtg(org.apache.poi.ss.formula.ptg.GreaterThanPtg) MultiplyPtg(org.apache.poi.ss.formula.ptg.MultiplyPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) ErrPtg(org.apache.poi.ss.formula.ptg.ErrPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) NamePtg(org.apache.poi.ss.formula.ptg.NamePtg) MemAreaPtg(org.apache.poi.ss.formula.ptg.MemAreaPtg) ConcatPtg(org.apache.poi.ss.formula.ptg.ConcatPtg) UnaryPlusPtg(org.apache.poi.ss.formula.ptg.UnaryPlusPtg) BoolPtg(org.apache.poi.ss.formula.ptg.BoolPtg) IntersectionPtg(org.apache.poi.ss.formula.ptg.IntersectionPtg) AbstractFunctionPtg(org.apache.poi.ss.formula.ptg.AbstractFunctionPtg) IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) UnionPtg(org.apache.poi.ss.formula.ptg.UnionPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) SubtractPtg(org.apache.poi.ss.formula.ptg.SubtractPtg) FuncPtg(org.apache.poi.ss.formula.ptg.FuncPtg) MissingArgPtg(org.apache.poi.ss.formula.ptg.MissingArgPtg) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) PowerPtg(org.apache.poi.ss.formula.ptg.PowerPtg) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) ParenthesisPtg(org.apache.poi.ss.formula.ptg.ParenthesisPtg) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) Test(org.junit.Test)

Aggregations

IntPtg (org.apache.poi.ss.formula.ptg.IntPtg)7 NumberPtg (org.apache.poi.ss.formula.ptg.NumberPtg)6 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)5 AttrPtg (org.apache.poi.ss.formula.ptg.AttrPtg)5 BoolPtg (org.apache.poi.ss.formula.ptg.BoolPtg)5 FuncPtg (org.apache.poi.ss.formula.ptg.FuncPtg)5 FuncVarPtg (org.apache.poi.ss.formula.ptg.FuncVarPtg)5 MultiplyPtg (org.apache.poi.ss.formula.ptg.MultiplyPtg)5 Ptg (org.apache.poi.ss.formula.ptg.Ptg)5 RefPtg (org.apache.poi.ss.formula.ptg.RefPtg)5 StringPtg (org.apache.poi.ss.formula.ptg.StringPtg)5 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)4 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)4 ArrayPtg (org.apache.poi.ss.formula.ptg.ArrayPtg)4 ConcatPtg (org.apache.poi.ss.formula.ptg.ConcatPtg)4 DividePtg (org.apache.poi.ss.formula.ptg.DividePtg)4 EqualPtg (org.apache.poi.ss.formula.ptg.EqualPtg)4 ErrPtg (org.apache.poi.ss.formula.ptg.ErrPtg)4 GreaterThanPtg (org.apache.poi.ss.formula.ptg.GreaterThanPtg)4 IntersectionPtg (org.apache.poi.ss.formula.ptg.IntersectionPtg)4