Search in sources :

Example 6 with FuncVarPtg

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

the class TestFormulaRecord method testWithConcat.

public void testWithConcat() {
    // =CHOOSE(2,A2,A3,A4)
    byte[] data = { 1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57, 64, 0, 0, 12, 0, 12, -4, 46, 0, // Int - 2
    30, // Int - 2
    2, // Int - 2
    0, // Attr
    25, // Attr
    4, // Attr
    3, // Attr
    0, // jumpTable
    8, // jumpTable
    0, // jumpTable
    17, // jumpTable
    0, // jumpTable
    26, // jumpTable
    0, // chooseOffset
    35, // chooseOffset
    0, // Ref - A2
    36, // Ref - A2
    1, // Ref - A2
    0, // Ref - A2
    0, // Ref - A2
    -64, // Attr
    25, // Attr
    8, // Attr
    21, // Attr
    0, // Ref - A3
    36, // Ref - A3
    2, // Ref - A3
    0, // Ref - A3
    0, // Ref - A3
    -64, // Attr
    25, // Attr
    8, // Attr
    12, // Attr
    0, // Ref - A4
    36, // Ref - A4
    3, // Ref - A4
    0, // Ref - A4
    0, // Ref - A4
    -64, // Attr
    25, // Attr
    8, // Attr
    3, // Attr
    0, // CHOOSE
    66, // CHOOSE
    4, // CHOOSE
    100, // CHOOSE
    0 };
    RecordInputStream inp = TestcaseRecordInputStream.create(FormatRecord.sid, data);
    FormulaRecord fr = new FormulaRecord(inp);
    Ptg[] ptgs = fr.getParsedExpression();
    assertEquals(9, ptgs.length);
    assertEquals(IntPtg.class, ptgs[0].getClass());
    assertEquals(AttrPtg.class, ptgs[1].getClass());
    assertEquals(RefPtg.class, ptgs[2].getClass());
    assertEquals(AttrPtg.class, ptgs[3].getClass());
    assertEquals(RefPtg.class, ptgs[4].getClass());
    assertEquals(AttrPtg.class, ptgs[5].getClass());
    assertEquals(RefPtg.class, ptgs[6].getClass());
    assertEquals(AttrPtg.class, ptgs[7].getClass());
    assertEquals(FuncVarPtg.class, ptgs[8].getClass());
    FuncVarPtg choose = (FuncVarPtg) ptgs[8];
    assertEquals("CHOOSE", choose.getName());
}
Also used : AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg)

Example 7 with FuncVarPtg

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

the class TestFormulaParserIf method testNestedFunctionIf.

/**
	 * Make sure the ptgs are generated properly with two functions embedded
	 *
	 */
public void testNestedFunctionIf() {
    Ptg[] ptgs = parseFormula("IF(A1=B1,AVERAGE(A1:B1),AVERAGE(A2:B2))");
    assertEquals(11, 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("Average Function set correctly", (ptgs[5] instanceof FuncVarPtg));
}
Also used : 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 8 with FuncVarPtg

use of org.apache.poi.ss.formula.ptg.FuncVarPtg 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)

Aggregations

FuncVarPtg (org.apache.poi.ss.formula.ptg.FuncVarPtg)8 Ptg (org.apache.poi.ss.formula.ptg.Ptg)8 AttrPtg (org.apache.poi.ss.formula.ptg.AttrPtg)6 IntPtg (org.apache.poi.ss.formula.ptg.IntPtg)5 RefPtg (org.apache.poi.ss.formula.ptg.RefPtg)5 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)4 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)4 BoolPtg (org.apache.poi.ss.formula.ptg.BoolPtg)4 FuncPtg (org.apache.poi.ss.formula.ptg.FuncPtg)4 MultiplyPtg (org.apache.poi.ss.formula.ptg.MultiplyPtg)4 StringPtg (org.apache.poi.ss.formula.ptg.StringPtg)4 IntersectionPtg (org.apache.poi.ss.formula.ptg.IntersectionPtg)3 MemAreaPtg (org.apache.poi.ss.formula.ptg.MemAreaPtg)3 MemFuncPtg (org.apache.poi.ss.formula.ptg.MemFuncPtg)3 RangePtg (org.apache.poi.ss.formula.ptg.RangePtg)3 UnionPtg (org.apache.poi.ss.formula.ptg.UnionPtg)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)2 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)2 ArrayPtg (org.apache.poi.ss.formula.ptg.ArrayPtg)2