Search in sources :

Example 6 with Ref3DPtg

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

the class TestFormulaShifter method testShiftSheet2.

@Test
public void testShiftSheet2() {
    // 4 sheets, move a sheet from pos 1 to pos 2, i.e. current 2 becomes 1, current 1 becomes pos 2 
    FormulaShifter shifter = FormulaShifter.createForSheetShift(1, 2);
    Ptg[] ptgs = new Ptg[] { new Ref3DPtg(new CellReference("first", 0, 0, true, true), 0), new Ref3DPtg(new CellReference("second", 0, 0, true, true), 1), new Ref3DPtg(new CellReference("third", 0, 0, true, true), 2), new Ref3DPtg(new CellReference("fourth", 0, 0, true, true), 3) };
    shifter.adjustFormula(ptgs, -1);
    assertEquals("formula previously pointing to sheet 0 should be unchanged", 0, ((Ref3DPtg) ptgs[0]).getExternSheetIndex());
    assertEquals("formula previously pointing to sheet 1 should now point to sheet 2", 2, ((Ref3DPtg) ptgs[1]).getExternSheetIndex());
    assertEquals("formula previously pointing to sheet 2 should now point to sheet 1", 1, ((Ref3DPtg) ptgs[2]).getExternSheetIndex());
    assertEquals("formula previously pointing to sheet 3 should be unchanged", 3, ((Ref3DPtg) ptgs[3]).getExternSheetIndex());
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) AreaErrPtg(org.apache.poi.ss.formula.ptg.AreaErrPtg) CellReference(org.apache.poi.ss.util.CellReference) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) Test(org.junit.Test)

Example 7 with Ref3DPtg

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

the class FormulaShifter method adjustPtgDueToSheetMove.

private Ptg adjustPtgDueToSheetMove(Ptg ptg) {
    if (ptg instanceof Ref3DPtg) {
        Ref3DPtg ref = (Ref3DPtg) ptg;
        int oldSheetIndex = ref.getExternSheetIndex();
        // 1. sheet is outside moved sheets, no change necessary
        if (oldSheetIndex < _srcSheetIndex && oldSheetIndex < _dstSheetIndex) {
            return null;
        }
        if (oldSheetIndex > _srcSheetIndex && oldSheetIndex > _dstSheetIndex) {
            return null;
        }
        // 2. ptg refers to the moved sheet
        if (oldSheetIndex == _srcSheetIndex) {
            ref.setExternSheetIndex(_dstSheetIndex);
            return ref;
        }
        // 3. new index is lower than old one => sheets get moved up
        if (_dstSheetIndex < _srcSheetIndex) {
            ref.setExternSheetIndex(oldSheetIndex + 1);
            return ref;
        }
        // 4. new index is higher than old one => sheets get moved down
        if (_dstSheetIndex > _srcSheetIndex) {
            ref.setExternSheetIndex(oldSheetIndex - 1);
            return ref;
        }
    }
    return null;
}
Also used : DeletedRef3DPtg(org.apache.poi.ss.formula.ptg.DeletedRef3DPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 8 with Ref3DPtg

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

the class TestNameRecord method testBug57923.

public void testBug57923() {
    NameRecord record = new NameRecord();
    assertEquals(0, record.getExternSheetNumber());
    record.setNameDefinition(new Ptg[] {});
    assertEquals(0, record.getExternSheetNumber());
    record.setNameDefinition(new Ptg[] { new NamePtg(1) });
    assertEquals(0, record.getExternSheetNumber());
    record.setNameDefinition(new Ptg[] { new Area3DPtg("area", 1) });
    assertEquals(1, record.getExternSheetNumber());
    record.setNameDefinition(new Ptg[] { new Ref3DPtg("A1", 1) });
    assertEquals(1, record.getExternSheetNumber());
}
Also used : NamePtg(org.apache.poi.ss.formula.ptg.NamePtg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 9 with Ref3DPtg

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

the class TestFormulaShifter method testShiftSheet.

@Test
public void testShiftSheet() {
    // 4 sheets, move a sheet from pos 2 to pos 0, i.e. current 0 becomes 1, current 1 becomes pos 2 
    FormulaShifter shifter = FormulaShifter.createForSheetShift(2, 0);
    Ptg[] ptgs = new Ptg[] { new Ref3DPtg(new CellReference("first", 0, 0, true, true), 0), new Ref3DPtg(new CellReference("second", 0, 0, true, true), 1), new Ref3DPtg(new CellReference("third", 0, 0, true, true), 2), new Ref3DPtg(new CellReference("fourth", 0, 0, true, true), 3) };
    shifter.adjustFormula(ptgs, -1);
    assertEquals("formula previously pointing to sheet 0 should now point to sheet 1", 1, ((Ref3DPtg) ptgs[0]).getExternSheetIndex());
    assertEquals("formula previously pointing to sheet 1 should now point to sheet 2", 2, ((Ref3DPtg) ptgs[1]).getExternSheetIndex());
    assertEquals("formula previously pointing to sheet 2 should now point to sheet 0", 0, ((Ref3DPtg) ptgs[2]).getExternSheetIndex());
    assertEquals("formula previously pointing to sheet 3 should be unchanged", 3, ((Ref3DPtg) ptgs[3]).getExternSheetIndex());
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) AreaErrPtg(org.apache.poi.ss.formula.ptg.AreaErrPtg) CellReference(org.apache.poi.ss.util.CellReference) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) Test(org.junit.Test)

Example 10 with Ref3DPtg

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

the class TestFormulaParser method confirmSingle3DRef.

private static void confirmSingle3DRef(Ptg[] ptgs, int expectedExternSheetIndex) {
    assertEquals(1, ptgs.length);
    Ptg ptg0 = ptgs[0];
    assertTrue(ptg0 instanceof Ref3DPtg);
    assertEquals(expectedExternSheetIndex, ((Ref3DPtg) ptg0).getExternSheetIndex());
}
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) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Aggregations

Ref3DPtg (org.apache.poi.ss.formula.ptg.Ref3DPtg)10 Ptg (org.apache.poi.ss.formula.ptg.Ptg)7 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)6 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)4 NameXPtg (org.apache.poi.ss.formula.ptg.NameXPtg)3 AreaErrPtg (org.apache.poi.ss.formula.ptg.AreaErrPtg)2 NamePtg (org.apache.poi.ss.formula.ptg.NamePtg)2 RefPtg (org.apache.poi.ss.formula.ptg.RefPtg)2 CellReference (org.apache.poi.ss.util.CellReference)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 NameRecord (org.apache.poi.hssf.record.NameRecord)1 HSSFEvaluationWorkbook (org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 WorkbookNotFoundException (org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException)1 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)1 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)1 Area3DPxg (org.apache.poi.ss.formula.ptg.Area3DPxg)1