aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-03-22 18:00:57 +0000
committerPJ Fanning <fanningpj@apache.org>2022-03-22 18:00:57 +0000
commit902d1487f7beba14d3335b55c35a1b04872582cc (patch)
treea546db3f4384a5bb23d558afdb5f9d8013dcf0b4
parentaff20dc6f9f70cf5deb08c04b69bf4639ca8029f (diff)
downloadpoi-902d1487f7beba14d3335b55c35a1b04872582cc.tar.gz
poi-902d1487f7beba14d3335b55c35a1b04872582cc.zip
[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
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java2
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java23
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<XSSFHyperlink> 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<XSSFHyperlink> 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");