From 79250e916f929fc9ebaa0ac20a481810d3f8ba0f Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 1 Dec 2017 17:47:29 +0000 Subject: [PATCH] bug 61840: add unit test showing that shiftRows does not produce #REF! formula errors if cells are not shifted above the first row git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1816892 13f79535-47bb-0310-9956-ffa450edef68 --- .../ss/usermodel/BaseTestSheetShiftRows.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java index ffd86f5f75..6bbfe0a916 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java @@ -22,6 +22,7 @@ import static org.apache.poi.POITestCase.testPassesNow; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; @@ -739,6 +740,30 @@ public abstract class BaseTestSheetShiftRows { wb.close(); } + + @Test + public void test61840_shifting_rows_up_does_not_produce_REF_errors() throws Exception { + Workbook wb = _testDataProvider.createWorkbook(); + Sheet sheet = wb.createSheet(); + Cell cell = sheet.createRow(4).createCell(0); + + cell.setCellFormula("(B5-C5)/B5"); + sheet.shiftRows(4, 4, -1); + + // Cell objects created before a row shift are still valid. + // The row number of those cell references will be shifted if + // the cell is within the shift range. + assertEquals("(B4-C4)/B4", cell.getCellFormula()); + + // New cell references are also valid. + Cell shiftedCell = sheet.getRow(3).getCell(0); + assertNotNull(shiftedCell); + assertEquals("(B4-C4)/B4", shiftedCell.getCellFormula()); + } + + + + private void createHyperlink(CreationHelper helper, Cell cell, HyperlinkType linkType, String ref) { cell.setCellValue(ref); -- 2.39.5