You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/08/11 21:25:01 UTC

svn commit: r1892249 - /poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java

Author: fanningpj
Date: Wed Aug 11 21:25:00 2021
New Revision: 1892249

URL: http://svn.apache.org/viewvc?rev=1892249&view=rev
Log:
support removing hyperlink from one cell when hyperlink is shared by many cells

Modified:
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java?rev=1892249&r1=1892248&r2=1892249&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFHyperlink.java Wed Aug 11 21:25:00 2021
@@ -32,6 +32,8 @@ import org.apache.poi.xssf.XSSFTestDataS
 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 ext
         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();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org