Search in sources :

Example 6 with MemFuncPtg

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

the class TestFormulaParser method testRange_bug46643.

@Test
public void testRange_bug46643() throws IOException {
    String formula = "Sheet1!A1:Sheet1!B3";
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet("Sheet1");
    Ptg[] ptgs = FormulaParser.parse(formula, HSSFEvaluationWorkbook.create(wb), FormulaType.CELL, -1, -1);
    if (ptgs.length == 3) {
        confirmTokenClasses(ptgs, Ref3DPtg.class, Ref3DPtg.class, RangePtg.class);
        fail("Identified bug 46643");
    }
    confirmTokenClasses(ptgs, MemFuncPtg.class, Ref3DPtg.class, Ref3DPtg.class, RangePtg.class);
    MemFuncPtg mf = (MemFuncPtg) ptgs[0];
    assertEquals(15, mf.getLenRefSubexpression());
    wb.close();
}
Also used : 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) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 7 with MemFuncPtg

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

the class TestFormulaParser method testIntersection.

@Test
public void testIntersection() throws IOException {
    String formula = "Sheet1!$B$2:$C$3 OFFSET(Sheet1!$E$2:$E$4, 1,Sheet1!$A$1) Sheet1!$D$6";
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet("Sheet1");
    Ptg[] ptgs = FormulaParser.parse(formula, HSSFEvaluationWorkbook.create(wb), FormulaType.CELL, -1);
    confirmTokenClasses(ptgs, // TODO - AttrPtg.class, // Excel prepends this
    MemFuncPtg.class, Area3DPtg.class, Area3DPtg.class, IntPtg.class, Ref3DPtg.class, FuncVarPtg.class, IntersectionPtg.class, Ref3DPtg.class, IntersectionPtg.class);
    MemFuncPtg mf = (MemFuncPtg) ptgs[0];
    assertEquals(45, mf.getLenRefSubexpression());
    // This used to be an error but now parses.  Union has the same behaviour.
    confirmTokenClasses("1 2", MemAreaPtg.class, IntPtg.class, IntPtg.class, IntersectionPtg.class);
    wb.close();
}
Also used : 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) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 8 with MemFuncPtg

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

the class TestFormulaParser method testUnion.

@Test
public void testUnion() throws IOException {
    String formula = "Sheet1!$B$2:$C$3,OFFSET(Sheet1!$E$2:$E$4,1,Sheet1!$A$1),Sheet1!$D$6";
    HSSFWorkbook wb = new HSSFWorkbook();
    wb.createSheet("Sheet1");
    Ptg[] ptgs = FormulaParser.parse(formula, HSSFEvaluationWorkbook.create(wb), FormulaType.CELL, -1);
    confirmTokenClasses(ptgs, // TODO - AttrPtg.class, // Excel prepends this
    MemFuncPtg.class, Area3DPtg.class, Area3DPtg.class, IntPtg.class, Ref3DPtg.class, FuncVarPtg.class, UnionPtg.class, Ref3DPtg.class, UnionPtg.class);
    MemFuncPtg mf = (MemFuncPtg) ptgs[0];
    assertEquals(45, mf.getLenRefSubexpression());
    // We don't check the type of the operands.
    confirmTokenClasses("1,2", MemAreaPtg.class, IntPtg.class, IntPtg.class, UnionPtg.class);
    wb.close();
}
Also used : 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) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 9 with MemFuncPtg

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

the class HSSFSheet method setRepeatingRowsAndColumns.

private void setRepeatingRowsAndColumns(CellRangeAddress rowDef, CellRangeAddress colDef) {
    int sheetIndex = _workbook.getSheetIndex(this);
    int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
    int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
    int col1 = -1;
    int col2 = -1;
    int row1 = -1;
    int row2 = -1;
    if (rowDef != null) {
        row1 = rowDef.getFirstRow();
        row2 = rowDef.getLastRow();
        if ((row1 == -1 && row2 != -1) || (row1 > row2) || (row1 < 0 || row1 > maxRowIndex) || (row2 < 0 || row2 > maxRowIndex)) {
            throw new IllegalArgumentException("Invalid row range specification");
        }
    }
    if (colDef != null) {
        col1 = colDef.getFirstColumn();
        col2 = colDef.getLastColumn();
        if ((col1 == -1 && col2 != -1) || (col1 > col2) || (col1 < 0 || col1 > maxColIndex) || (col2 < 0 || col2 > maxColIndex)) {
            throw new IllegalArgumentException("Invalid column range specification");
        }
    }
    short externSheetIndex = _workbook.getWorkbook().checkExternSheet(sheetIndex);
    boolean setBoth = rowDef != null && colDef != null;
    boolean removeAll = rowDef == null && colDef == null;
    HSSFName name = _workbook.getBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
    if (removeAll) {
        if (name != null) {
            _workbook.removeName(name);
        }
        return;
    }
    if (name == null) {
        name = _workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
    }
    List<Ptg> ptgList = new ArrayList<Ptg>();
    if (setBoth) {
        // 2 * Area3DPtg.SIZE + UnionPtg.SIZE
        final int exprsSize = 2 * 11 + 1;
        ptgList.add(new MemFuncPtg(exprsSize));
    }
    if (colDef != null) {
        Area3DPtg colArea = new Area3DPtg(0, maxRowIndex, col1, col2, false, false, false, false, externSheetIndex);
        ptgList.add(colArea);
    }
    if (rowDef != null) {
        Area3DPtg rowArea = new Area3DPtg(row1, row2, 0, maxColIndex, false, false, false, false, externSheetIndex);
        ptgList.add(rowArea);
    }
    if (setBoth) {
        ptgList.add(UnionPtg.instance);
    }
    Ptg[] ptgs = new Ptg[ptgList.size()];
    ptgList.toArray(ptgs);
    name.setNameDefinition(ptgs);
    HSSFPrintSetup printSetup = getPrintSetup();
    printSetup.setValidSettings(false);
    setActive(true);
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) UnionPtg(org.apache.poi.ss.formula.ptg.UnionPtg) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) ArrayList(java.util.ArrayList)

Aggregations

MemFuncPtg (org.apache.poi.ss.formula.ptg.MemFuncPtg)9 Ptg (org.apache.poi.ss.formula.ptg.Ptg)9 UnionPtg (org.apache.poi.ss.formula.ptg.UnionPtg)8 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)7 AttrPtg (org.apache.poi.ss.formula.ptg.AttrPtg)7 MemAreaPtg (org.apache.poi.ss.formula.ptg.MemAreaPtg)7 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)6 FuncVarPtg (org.apache.poi.ss.formula.ptg.FuncVarPtg)6 IntersectionPtg (org.apache.poi.ss.formula.ptg.IntersectionPtg)6 ParenthesisPtg (org.apache.poi.ss.formula.ptg.ParenthesisPtg)6 RangePtg (org.apache.poi.ss.formula.ptg.RangePtg)6 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)5 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)5 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)5 ArrayPtg (org.apache.poi.ss.formula.ptg.ArrayPtg)5 BoolPtg (org.apache.poi.ss.formula.ptg.BoolPtg)5 ConcatPtg (org.apache.poi.ss.formula.ptg.ConcatPtg)5 DividePtg (org.apache.poi.ss.formula.ptg.DividePtg)5 EqualPtg (org.apache.poi.ss.formula.ptg.EqualPtg)5 ErrPtg (org.apache.poi.ss.formula.ptg.ErrPtg)5