From aff20dc6f9f70cf5deb08c04b69bf4639ca8029f Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 22 Mar 2022 17:55:53 +0000 Subject: [PATCH] [bug-65973] partial fix for removing hyperlinks that span multiple cells git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899138 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/TestXSSFSheet.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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 fda59a105a..6fddce330c 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 @@ -2288,7 +2288,7 @@ public final class TestXSSFSheet extends BaseTestXSheet { } @Test - void testRowShiftWithHyperlink() throws IOException { + void testRowShiftWithHyperlink1() throws IOException { try (XSSFWorkbook wb = createWorkbookForRowShiftWithHyperlink1(true)) { XSSFSheet sheet = wb.getSheetAt(0); List hyperlinks = sheet.getHyperlinkList(); @@ -2306,6 +2306,25 @@ public final class TestXSSFSheet extends BaseTestXSheet { } } + @Test + void testRowShiftWithHyperlink2() 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, -2); + assertEquals(1, sheet.getLastRowNum()); + XSSFRow row0 = sheet.getRow(0); + XSSFRow row1 = sheet.getRow(1); + assertEquals("row2", row0.getCell(0).getStringCellValue()); + assertEquals("row3", row1.getCell(0).getStringCellValue()); + assertEquals(0, sheet.getHyperlinkList().size()); + } + } + private XSSFWorkbook createWorkbookForRowShiftWithHyperlink1(boolean hyperlinkOneRow) { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet("Sheet1");