Bug 54524: Fix border case in FormulaShifter

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1517676 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2013-08-26 20:09:19 +00:00
parent 84ef8c5970
commit 17e8880dcd
4 changed files with 21 additions and 1 deletions

View File

@ -85,6 +85,7 @@ public final class FormulaShifter {
return new FormulaShifter(srcSheetIndex, dstSheetIndex); return new FormulaShifter(srcSheetIndex, dstSheetIndex);
} }
@Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
@ -322,7 +323,7 @@ public final class FormulaShifter {
aptg.setFirstRow(destLastRowIndex+1); aptg.setFirstRow(destLastRowIndex+1);
return aptg; return aptg;
} }
if (destFirstRowIndex < aLastRow && aLastRow <= destLastRowIndex) { if (destFirstRowIndex <= aLastRow && aLastRow < destLastRowIndex) {
// dest rows overlap bottom of area // dest rows overlap bottom of area
// - truncate the bottom // - truncate the bottom
aptg.setLastRow(destFirstRowIndex-1); aptg.setLastRow(destFirstRowIndex-1);

View File

@ -17,8 +17,13 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.io.IOException;
import org.apache.poi.ss.usermodel.BaseTestSheetShiftRows; 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.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
/** /**
* @author Yegor Kozlov * @author Yegor Kozlov
@ -36,4 +41,17 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
public void testShiftWithComments() { // disabled test from superclass public void testShiftWithComments() { // disabled test from superclass
// TODO - support shifting of comments. // 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());
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.poi.ss.formula; package org.apache.poi.ss.formula;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.ss.formula.ptg.AreaErrPtg; import org.apache.poi.ss.formula.ptg.AreaErrPtg;
import org.apache.poi.ss.formula.ptg.AreaPtg; import org.apache.poi.ss.formula.ptg.AreaPtg;
import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.Ptg;

Binary file not shown.