From 902d1487f7beba14d3335b55c35a1b04872582cc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 22 Mar 2022 18:00:57 +0000 Subject: [PATCH] [bug-65973] fix for removing hyperlinks that span multiple cells git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899139 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFSheet.java | 2 -- .../poi/xssf/usermodel/TestXSSFSheet.java | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 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 7ba29b06ee..cd001179c6 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 @@ -3085,8 +3085,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx if (hyperlinks != null) { for (XSSFHyperlink link : new ArrayList<>(hyperlinks)) { CellRangeAddress range = CellRangeAddress.valueOf(link.getCellRef()); - //TODO handle case where hyperlink ref spans many rows (https://bz.apache.org/bugzilla/show_bug.cgi?id=65973) - //but where only some rows are being removed and others are not (range will need to be modified) if (range.getFirstRow() == range.getLastRow() && rowsToRemoveSet.contains(range.getFirstRow())) { removeHyperlink(link); } else if (range.getFirstRow() != range.getLastRow()) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 6fddce330c..964e9a7d8e 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -2325,6 +2325,29 @@ public final class TestXSSFSheet extends BaseTestXSheet { } } + @Test + void testRowShiftWithHyperlink3() throws IOException { + try (XSSFWorkbook wb = createWorkbookForRowShiftWithHyperlink1(false)) { + XSSFSheet sheet = wb.getSheetAt(0); + List hyperlinks = sheet.getHyperlinkList(); + assertEquals(1, hyperlinks.size()); + assertEquals("B1:B2", hyperlinks.get(0).getCellRef()); + assertEquals(3, sheet.getLastRowNum()); + + sheet.shiftRows(2, 3, -1); + assertEquals(2, sheet.getLastRowNum()); + XSSFRow row0 = sheet.getRow(0); + XSSFRow row1 = sheet.getRow(1); + XSSFRow row2 = sheet.getRow(2); + assertEquals("row0", row0.getCell(0).getStringCellValue()); + assertEquals("row2", row1.getCell(0).getStringCellValue()); + assertEquals("row3", row2.getCell(0).getStringCellValue()); + List hyperlinks2 = sheet.getHyperlinkList(); + assertEquals(1, hyperlinks2.size()); + assertEquals("B1", hyperlinks2.get(0).getCellRef()); + } + } + private XSSFWorkbook createWorkbookForRowShiftWithHyperlink1(boolean hyperlinkOneRow) { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet("Sheet1");