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());
}
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;
}
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());
}
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());
}
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());
}
Aggregations