diff options
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java | 11 | ||||
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java | 25 | ||||
-rw-r--r-- | test-data/spreadsheet/bug65306.xlsx | bin | 0 -> 9515 bytes |
3 files changed, 32 insertions, 4 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index e953378dee..48436bb826 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -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 diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 156e89cf25..ae0770f555 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -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); + } + } + } } diff --git a/test-data/spreadsheet/bug65306.xlsx b/test-data/spreadsheet/bug65306.xlsx Binary files differnew file mode 100644 index 0000000000..a2af1869fd --- /dev/null +++ b/test-data/spreadsheet/bug65306.xlsx |