]> source.dussan.org Git - poi.git/commitdiff
bug 60601: unlink hyperlinks from a sheet if all hyperlinks have been removed. Patch...
authorJaven O'Neal <onealj@apache.org>
Thu, 19 Jan 2017 07:44:25 +0000 (07:44 +0000)
committerJaven O'Neal <onealj@apache.org>
Thu, 19 Jan 2017 07:44:25 +0000 (07:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779426 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

index bde93d663caec5062d3b8f5d1baad0a466d5c1af..b7b30126cbd3b7b8884ddfec26bf767596c1c3ee 100644 (file)
@@ -3484,6 +3484,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
             }
             worksheet.getHyperlinks().setHyperlinkArray(ctHls);
         }
+        else {
+            worksheet.unsetHyperlinks();
+        }
 
         int minCell=Integer.MAX_VALUE, maxCell=Integer.MIN_VALUE;
         for(XSSFRow row : _rows.values()){
index 4e7179109b04b67999dd1b1a804e766f1c4f584e..8e010a6c055bc70d4a9c920c659a63d5f2cac5af 100644 (file)
@@ -1231,6 +1231,29 @@ public abstract class BaseTestSheet {
         
         workbook.close();
     }
+    
+    @Test
+    public void removeAllHyperlinks() throws IOException {
+        Workbook workbook = _testDataProvider.createWorkbook();
+        Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL);
+        hyperlink.setAddress("https://poi.apache.org/");
+        Sheet sheet = workbook.createSheet();
+        Cell cell = sheet.createRow(5).createCell(1);
+        cell.setHyperlink(hyperlink);
+        
+        assertEquals(1, workbook.getSheetAt(0).getHyperlinkList().size());
+        // Save a workbook with a hyperlink
+        Workbook workbook2 = _testDataProvider.writeOutAndReadBack(workbook);
+        assertEquals(1, workbook2.getSheetAt(0).getHyperlinkList().size());
+        
+        // Remove all hyperlinks from a saved workbook
+        workbook2.getSheetAt(0).getRow(5).getCell(1).removeHyperlink();
+        assertEquals(0, workbook2.getSheetAt(0).getHyperlinkList().size());
+        
+        // Verify that hyperlink was removed from workbook after writing out
+        Workbook workbook3 = _testDataProvider.writeOutAndReadBack(workbook2);
+        assertEquals(0, workbook3.getSheetAt(0).getHyperlinkList().size());
+    }
 
 
     @Test