]> source.dussan.org Git - poi.git/commitdiff
Fix bug #55050 - If the start+end row and cell are the same on an AreaPtg, avoid...
authorNick Burch <nick@apache.org>
Thu, 31 Jul 2014 16:06:43 +0000 (16:06 +0000)
committerNick Burch <nick@apache.org>
Thu, 31 Jul 2014 16:06:43 +0000 (16:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614928 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/ptg/AreaPtgBase.java
src/testcases/org/apache/poi/ss/formula/ptg/TestAreaPtg.java

index 4df3314440fa939f04b6be6553f1bf0f75a8667f..5b77b09fed7d38d1240ee3e80776071eb08d8acb 100644 (file)
@@ -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);
index 0dd72661fc8b09d9cded8610fb87677412fe1932..0dcbeafc5c2dc62d0fe4f8e5dbdd7b842dbab6c8 100644 (file)
@@ -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)";