aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-08-11 21:25:00 +0000
committerPJ Fanning <fanningpj@apache.org>2021-08-11 21:25:00 +0000
commitef61f3da7c814296843ac95127a7c5ab410b1bf3 (patch)
tree20baab2a0ef9ffcb987c1d43a77b9041b7d79ba1
parent80b73d65b13f1d6576a33a352d1c384de481dbc4 (diff)
downloadpoi-ef61f3da7c814296843ac95127a7c5ab410b1bf3.tar.gz
poi-ef61f3da7c814296843ac95127a7c5ab410b1bf3.zip
support removing hyperlink from one cell when hyperlink is shared by many cells
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892249 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
index d278785d57..05892c9b8f 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
@@ -32,6 +32,8 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.jupiter.api.Test;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.*;
@@ -491,6 +493,32 @@ public final class TestXSSFHyperlink extends BaseTestHyperlink {
testRemoveSharedHyperlinkFromOneCell("D3:D5", new CellAddress("D5"));
}
+ @Test
+ void testRemoveSharedHyperlinkFromOneCellWithCellRefs() throws IOException {
+ try (XSSFWorkbook wb = new XSSFWorkbook()) {
+ XSSFSheet sheet = wb.createSheet();
+ XSSFHyperlink hyperlink = new XSSFHyperlink(HyperlinkType.URL);
+ hyperlink.setAddress("https://poi.apache.org");
+ hyperlink.setLocation("poi-location");
+ hyperlink.setLabel("poi-label");
+ hyperlink.setCellReference("A1:E5");
+ sheet.addHyperlink(hyperlink);
+ CellAddress cellAddress = new CellAddress("C3");
+ sheet.removeHyperlink(cellAddress.getRow(), cellAddress.getColumn());
+ assertNull(sheet.getHyperlink(cellAddress), "cell " + cellAddress.formatAsString() + "should no longer has a hyperlink");
+ ArrayList<String> newRefs = new ArrayList<>();
+ for (XSSFHyperlink testHyperlink : sheet.getHyperlinkList()) {
+ newRefs.add(testHyperlink.getCellRef());
+ }
+ assertEquals(4, newRefs.size());
+ HashSet<String> set = new HashSet<>(newRefs);
+ assertTrue(set.contains("A1:B5"), "contains A1:B5");
+ assertTrue(set.contains("D1:E5"), "contains D1:E5");
+ assertTrue(set.contains("C1:C2"), "contains C1:C2");
+ assertTrue(set.contains("C4:C5"), "contains C4:C5");
+ }
+ }
+
private void testRemoveSharedHyperlinkFromOneCell(String area, CellAddress cellAddress) throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();