]> source.dussan.org Git - poi.git/commitdiff
bug 60601: hyperlinks have to be removed one by one to avoid other errors
authorJaven O'Neal <onealj@apache.org>
Thu, 19 Jan 2017 08:09:11 +0000 (08:09 +0000)
committerJaven O'Neal <onealj@apache.org>
Thu, 19 Jan 2017 08:09:11 +0000 (08:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779429 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

index b7b30126cbd3b7b8884ddfec26bf767596c1c3ee..d6fc4353e6c953e8457ba6ff12041ec500a14548 100644 (file)
@@ -3485,7 +3485,18 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
             worksheet.getHyperlinks().setHyperlinkArray(ctHls);
         }
         else {
-            worksheet.unsetHyperlinks();
+            // For some reason, we have to remove the hyperlinks one by one from the CTHyperlinks array
+            // rather than unsetting or resetting the hyperlink array.
+            //worksheet.getHyperlinks().setHyperlinkArray(new CTHyperlink[0]);
+            //worksheet.unsetHyperlinks();
+            if (worksheet.getHyperlinks() != null) {
+                final int count = worksheet.getHyperlinks().sizeOfHyperlinkArray();
+                for (int i=count-1; i>=0; i--) {
+                    worksheet.getHyperlinks().removeHyperlink(i);
+                }
+            } else {
+                // nothing to do
+            }
         }
 
         int minCell=Integer.MAX_VALUE, maxCell=Integer.MIN_VALUE;