Browse Source

[bug-65306] issue with shift rows that remove rows and how shared formulas are affected

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894089 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_0
PJ Fanning 2 years ago
parent
commit
7d47c205e9

+ 7
- 4
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java View File

@@ -2951,8 +2951,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* Calls shiftRows(startRow, endRow, n, false, false);
*
* <p>
* Additionally shifts merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted).
* Additionally, shifts merged regions that are completely defined in these
* rows (i.e. merged 2 cells on a row to be shifted).
* @param startRow the row to start shifting
* @param endRow the row to end shifting
* @param n the number of rows to shift
@@ -2968,8 +2968,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* Code ensures that rows don't wrap around
*
* <p>
* Additionally shifts merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted). All merged regions that are
* Additionally, shifts merged regions that are completely defined in these
* rows (i.e. merged 2 cells on a row to be shifted). All merged regions that are
* completely overlaid by shifting will be deleted.
*
* @param startRow the row to start shifting
@@ -3054,6 +3054,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {

// check if we should remove this row as it will be overwritten by the data later
if (shouldRemoveRow(startRow, endRow, n, rownum)) {
for (Cell c : row) {
c.setBlank();
}
// remove row from worksheet.getSheetData row array
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
//noinspection UnnecessaryBoxing

+ 25
- 0
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java View File

@@ -3598,4 +3598,29 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals("2-1,2-1,1+2,2-1,2-1,3+3,3+3,3+3,2-1,2-1,", sb.toString());
}
}

@Test
void testBug65306() throws IOException {
try (XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("bug65306.xlsx")) {
XSSFSheet sheet = wb1.getSheetAt(0);
assertNotNull(sheet);
XSSFCell a1 = sheet.getRow(0).getCell(0);
XSSFCell b1 = sheet.getRow(0).getCell(1);
XSSFCell a2 = sheet.getRow(1).getCell(0);
XSSFCell b2 = sheet.getRow(1).getCell(1);
assertEquals(1.0, a1.getNumericCellValue());
assertEquals(2.0, a2.getNumericCellValue());
assertEquals("$A$1+3*$A$2", b1.getCellFormula());
assertEquals("$A$1+3*$A$2", b2.getCellFormula());
sheet.shiftRows(1, 1, -1);
assertNull(sheet.getRow(1), "row 2 was removed?");
a1 = sheet.getRow(0).getCell(0);
b1 = sheet.getRow(0).getCell(1);
assertEquals(2.0, a1.getNumericCellValue());
assertEquals("#REF!+3*$A$1", b1.getCellFormula());
try (FileOutputStream fos = new FileOutputStream("abc.xlsx")) {
wb1.write(fos);
}
}
}
}

BIN
test-data/spreadsheet/bug65306.xlsx View File


Loading…
Cancel
Save