Search in sources :

Example 1 with ArrayPtg

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

the class TestFormulaParser method testParseStringElementInArray.

@Test
public void testParseStringElementInArray() {
    Ptg[] ptgs;
    ptgs = parseFormula("MAX({\"5\"},3)");
    confirmTokenClasses(ptgs, ArrayPtg.class, IntPtg.class, FuncVarPtg.class);
    Object element = ((ArrayPtg) ptgs[0]).getTokenArrayValues()[0][0];
    if (element instanceof UnicodeString) {
        // this would cause ClassCastException below
        fail("Wrong encoding of array element value");
    }
    assertEquals(String.class, element.getClass());
    // make sure the formula encodes OK
    int encSize = Ptg.getEncodedSize(ptgs);
    byte[] data = new byte[encSize];
    Ptg.serializePtgs(ptgs, data, 0);
    byte[] expData = HexRead.readFromString(// tArray
    "20 00 00 00 00 00 00 00 " + // tInt(3)
    "1E 03 00 " + // tFuncVar(MAX) 2-arg
    "42 02 07 00 " + // Array data: 1 col, 1 row
    "00 00 00 " + // elem (type=string, len=1, "5")
    "02 01 00 00 35");
    assertArrayEquals(expData, data);
    int initSize = Ptg.getEncodedSizeWithoutArrayData(ptgs);
    Ptg[] ptgs2 = Ptg.readTokens(initSize, new LittleEndianByteArrayInputStream(data));
    confirmTokenClasses(ptgs2, ArrayPtg.class, IntPtg.class, FuncVarPtg.class);
}
Also used : ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) 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) LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) Test(org.junit.Test)

Example 2 with ArrayPtg

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

the class FormulaParser method parseArray.

private ParseNode parseArray() {
    List<Object[]> rowsData = new ArrayList<Object[]>();
    while (true) {
        Object[] singleRowData = parseArrayRow();
        rowsData.add(singleRowData);
        if (look == '}') {
            break;
        }
        if (look != ';') {
            throw expected("'}' or ';'");
        }
        Match(';');
    }
    int nRows = rowsData.size();
    Object[][] values2d = new Object[nRows][];
    rowsData.toArray(values2d);
    int nColumns = values2d[0].length;
    checkRowLengths(values2d, nColumns);
    return new ParseNode(new ArrayPtg(values2d));
}
Also used : ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) ArrayList(java.util.ArrayList)

Example 3 with ArrayPtg

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

the class TestNameRecord method assert_bug50244.

private void assert_bug50244(NameRecord nr) {
    assertEquals("wDataGruppeSerie.", nr.getNameText());
    Ptg[] ptg = nr.getNameDefinition();
    assertEquals(1, ptg.length);
    ArrayPtg arr = (ArrayPtg) ptg[0];
    assertEquals(696, arr.getRowCount());
    assertEquals(1, arr.getColumnCount());
    Object[][] vals = arr.getTokenArrayValues();
    assertEquals("1.T20.001", vals[0][0]);
    assertEquals("1.T20.010", vals[vals.length - 1][0]);
}
Also used : ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) NamePtg(org.apache.poi.ss.formula.ptg.NamePtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 4 with ArrayPtg

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

the class TestFormulaParser method testParseArray.

@Test
public void testParseArray() {
    Ptg[] ptgs;
    ptgs = parseFormula("mode({1,2,2,#REF!;FALSE,3,3,2})");
    confirmTokenClasses(ptgs, ArrayPtg.class, FuncVarPtg.class);
    assertEquals("{1,2,2,#REF!;FALSE,3,3,2}", ptgs[0].toFormulaString());
    ArrayPtg aptg = (ArrayPtg) ptgs[0];
    Object[][] values = aptg.getTokenArrayValues();
    assertEquals(ErrorConstant.valueOf(FormulaError.REF.getCode()), values[0][3]);
    assertEquals(Boolean.FALSE, values[1][0]);
}
Also used : ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) 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) Test(org.junit.Test)

Aggregations

ArrayPtg (org.apache.poi.ss.formula.ptg.ArrayPtg)4 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)3 NamePtg (org.apache.poi.ss.formula.ptg.NamePtg)3 Ptg (org.apache.poi.ss.formula.ptg.Ptg)3 Ref3DPtg (org.apache.poi.ss.formula.ptg.Ref3DPtg)3 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)2 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)2 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)2 AttrPtg (org.apache.poi.ss.formula.ptg.AttrPtg)2 BoolPtg (org.apache.poi.ss.formula.ptg.BoolPtg)2 ConcatPtg (org.apache.poi.ss.formula.ptg.ConcatPtg)2 DividePtg (org.apache.poi.ss.formula.ptg.DividePtg)2 EqualPtg (org.apache.poi.ss.formula.ptg.EqualPtg)2 ErrPtg (org.apache.poi.ss.formula.ptg.ErrPtg)2 FuncPtg (org.apache.poi.ss.formula.ptg.FuncPtg)2 FuncVarPtg (org.apache.poi.ss.formula.ptg.FuncVarPtg)2 GreaterThanPtg (org.apache.poi.ss.formula.ptg.GreaterThanPtg)2 IntPtg (org.apache.poi.ss.formula.ptg.IntPtg)2 IntersectionPtg (org.apache.poi.ss.formula.ptg.IntersectionPtg)2 MemAreaPtg (org.apache.poi.ss.formula.ptg.MemAreaPtg)2