Procházet zdrojové kódy

[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 před 2 roky
rodič
revize
7d47c205e9

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

* Calls shiftRows(startRow, endRow, n, false, false); * Calls shiftRows(startRow, endRow, n, false, false);
* *
* <p> * <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 startRow the row to start shifting
* @param endRow the row to end shifting * @param endRow the row to end shifting
* @param n the number of rows to shift * @param n the number of rows to shift
* Code ensures that rows don't wrap around * Code ensures that rows don't wrap around
* *
* <p> * <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. * completely overlaid by shifting will be deleted.
* *
* @param startRow the row to start shifting * @param startRow the row to start shifting


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

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

assertEquals("2-1,2-1,1+2,2-1,2-1,3+3,3+3,3+3,2-1,2-1,", sb.toString()); 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ární
test-data/spreadsheet/bug65306.xlsx Zobrazit soubor


Načítá se…
Zrušit
Uložit