From 17de55241feb86342885cf7c94b0f32bdc4439e7 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 31 Jul 2014 16:06:43 +0000 Subject: [PATCH] Fix bug #55050 - If the start+end row and cell are the same on an AreaPtg, avoid inverting the relative flag git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614928 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/formula/ptg/AreaPtgBase.java | 4 +-- .../poi/ss/formula/ptg/TestAreaPtg.java | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java b/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java index 4df3314440..5b77b09fed 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java @@ -71,7 +71,7 @@ public abstract class AreaPtgBase extends OperandPtg implements AreaI { protected AreaPtgBase(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) { - if (lastRow > firstRow) { + if (lastRow >= firstRow) { setFirstRow(firstRow); setLastRow(lastRow); setFirstRowRelative(firstRowRelative); @@ -83,7 +83,7 @@ public abstract class AreaPtgBase extends OperandPtg implements AreaI { setLastRowRelative(firstRowRelative); } - if (lastColumn > firstColumn) { + if (lastColumn >= firstColumn) { setFirstColumn(firstColumn); setLastColumn(lastColumn); setFirstColRelative(firstColRelative); diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java index 0dd72661fc..0dcbeafc5c 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java @@ -71,6 +71,35 @@ public final class TestAreaPtg extends TestCase { assertEquals(lc , aptg.getLastColumn() ); } + public void testAbsoluteRelativeRefs() { + AreaPtg sca1 = new AreaPtg(4, 5, 6, 7, true, false, true, false); + AreaPtg sca2 = new AreaPtg(4, 5, 6, 7, false, true, false, true); + AreaPtg sca3 = new AreaPtg(5, 5, 7, 7, true, false, true, false); + AreaPtg sca4 = new AreaPtg(5, 5, 7, 7, false, true, false, true); + + assertEquals("first rel., last abs.", "G5:$H$6", sca1.toFormulaString()); + assertEquals("first abs., last rel.", "$G$5:H6", sca2.toFormulaString()); + assertEquals("first rel., last abs.", "H6:$H$6", sca3.toFormulaString()); + assertEquals("first abs., last rel.", "$H$6:H6", sca4.toFormulaString()); + + AreaPtg cla1 = cloneArea(sca1); + AreaPtg cla2 = cloneArea(sca2); + AreaPtg cla3 = cloneArea(sca3); + AreaPtg cla4 = cloneArea(sca4); + + assertEquals("first rel., last abs.", "G5:$H$6", cla1.toFormulaString()); + assertEquals("first abs., last rel.", "$G$5:H6", cla2.toFormulaString()); + assertEquals("first rel., last abs.", "H6:$H$6", cla3.toFormulaString()); + assertEquals("first abs., last rel.", "$H$6:H6", cla4.toFormulaString()); + } + private AreaPtg cloneArea(AreaPtg a) + { + return new AreaPtg( + a.getFirstRow(), a.getLastRow(), a.getFirstColumn(), a.getLastColumn(), + a.isFirstRowRelative(), a.isLastRowRelative(), a.isFirstColRelative(), a.isLastColRelative() + ); + } + public void testFormulaParser() { String formula1="SUM($E$5:$E$6)"; -- 2.39.5