From 17e8880dcd526e9c2a390e2392463e9f8a1d9563 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 26 Aug 2013 20:09:19 +0000 Subject: [PATCH] Bug 54524: Fix border case in FormulaShifter git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1517676 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/formula/FormulaShifter.java | 3 ++- .../usermodel/TestXSSFSheetShiftRows.java | 18 ++++++++++++++++++ .../poi/ss/formula/TestFormulaShifter.java | 1 + test-data/spreadsheet/54524.xlsx | Bin 0 -> 13777 bytes 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test-data/spreadsheet/54524.xlsx diff --git a/src/java/org/apache/poi/ss/formula/FormulaShifter.java b/src/java/org/apache/poi/ss/formula/FormulaShifter.java index 32da2b17a..74804a884 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaShifter.java +++ b/src/java/org/apache/poi/ss/formula/FormulaShifter.java @@ -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); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java index a8e7374c9..aa2ae2280 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java @@ -17,8 +17,13 @@ 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()); + } } diff --git a/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java b/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java index 79e42c2c5..e3e955850 100644 --- a/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java +++ b/src/testcases/org/apache/poi/ss/formula/TestFormulaShifter.java @@ -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 index 0000000000000000000000000000000000000000..5a16447e047c8584bee9495e05ba6d255b4e5b1c GIT binary patch literal 13777 zcmeHuWmp{B(k=vdcPDsocM0wU2<{r(EjR>s32p%rg1f`u65QS0-3Pgo?6c3_CuiUL z|9kG&^UO@I?p1I1R9CI4wdx%uSqMl>FlaDXFfcGOuoY%Z!enqTum&hFFbuE(aBWdL zTW3>SXMI%NbsFQo~ZSk*gUB9}wLe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