]> source.dussan.org Git - poi.git/commitdiff
Bug 54524: Fix border case in FormulaShifter
authorDominik Stadler <centic@apache.org>
Mon, 26 Aug 2013 20:09:19 +0000 (20:09 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 26 Aug 2013 20:09:19 +0000 (20:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1517676 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/FormulaShifter.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java
test-data/spreadsheet/54524.xlsx [new file with mode: 0644]

index 32da2b17a4f8e8625f997fb4fa1ff82085095c03..74804a8845bbe4d4316170e64d72298f8c7531d1 100644 (file)
@@ -85,6 +85,7 @@ public final class FormulaShifter {
         return new FormulaShifter(srcSheetIndex, dstSheetIndex);
     }
 
+       @Override
        public String toString() {
                StringBuffer sb = new StringBuffer();
 
@@ -322,7 +323,7 @@ public final class FormulaShifter {
                        aptg.setFirstRow(destLastRowIndex+1);
                        return aptg;
                }
-               if (destFirstRowIndex < aLastRow && aLastRow <= destLastRowIndex) {
+               if (destFirstRowIndex <= aLastRow && aLastRow < destLastRowIndex) {
                        // dest rows overlap bottom of area
                        // - truncate the bottom
                        aptg.setLastRow(destFirstRowIndex-1);
index a8e7374c96a854f279ee11b9f50cdf95b87f6564..aa2ae228095447bb7dcef79ec2318d5a1668ba0c 100644 (file)
 
 package org.apache.poi.xssf.usermodel;
 
+import java.io.IOException;
+
 import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.util.CellUtil;
 import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFTestDataSamples;
 
 /**
  * @author Yegor Kozlov
@@ -36,4 +41,17 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
     public void testShiftWithComments() { // disabled test from superclass
         // TODO - support shifting of comments.
     }
+
+       public void testBug54524() throws IOException {
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("54524.xlsx");
+        XSSFSheet sheet = workbook.getSheetAt(0);
+               sheet.shiftRows(3, 5, -1);
+
+        Cell cell = CellUtil.getCell(sheet.getRow(1), 0);
+               assertEquals(1.0, cell.getNumericCellValue());
+               cell = CellUtil.getCell(sheet.getRow(2), 0);
+               assertEquals("SUM(A2:A2)", cell.getCellFormula());
+               cell = CellUtil.getCell(sheet.getRow(3), 0);
+               assertEquals("X", cell.getStringCellValue());
+       }
 }
index 79e42c2c5efeaa0f7898ab3efc2115593ecae94d..e3e955850ad5aab609c3c6914358a7373a363ae4 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.ss.formula;
 
 import junit.framework.TestCase;
+
 import org.apache.poi.ss.formula.ptg.AreaErrPtg;
 import org.apache.poi.ss.formula.ptg.AreaPtg;
 import org.apache.poi.ss.formula.ptg.Ptg;
diff --git a/test-data/spreadsheet/54524.xlsx b/test-data/spreadsheet/54524.xlsx
new file mode 100644 (file)
index 0000000..5a16447
Binary files /dev/null and b/test-data/spreadsheet/54524.xlsx differ