diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index aad9a5367..801b21875 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + Support for hyperlinks in SXSSF 49933 - Word 6/95 documents with sections cause ArrayIndexOutOfBoundsException 51469 - XSSF support for row styles, to match existing HSSF functionality 51476 - Correct XSSF cell formatting in HTML export diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java index b6423189a..bd57fc3de 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java @@ -26,7 +26,8 @@ import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.formula.FormulaParseException; import org.apache.poi.ss.util.CellRangeAddress; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType; +import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.usermodel.XSSFHyperlink; /** * Streaming version of XSSFRow implementing the "BigGridDemo" strategy. @@ -570,6 +571,15 @@ public class SXSSFCell implements Cell public void setHyperlink(Hyperlink link) { setProperty(Property.HYPERLINK,link); + + XSSFHyperlink xssfobj = (XSSFHyperlink)link; + // Assign to us + CellReference ref = new CellReference(getRowIndex(), getColumnIndex()); + xssfobj.getCTHyperlink().setRef( ref.formatAsString() ); + + // Add to the lists + ((SXSSFSheet)getSheet())._sh.addHyperlink(xssfobj); + } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 42c70e8c8..1185b562a 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -917,7 +917,7 @@ public final class XSSFCell implements Cell { link.setCellReference( new CellReference(_row.getRowNum(), _cellNum).formatAsString() ); // Add to the lists - getSheet().setCellHyperlink(link); + getSheet().addHyperlink(link); } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java index c472911e8..21fd54b84 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java @@ -88,9 +88,9 @@ public class XSSFHyperlink implements Hyperlink { } /** - * Returns the underlying hyperlink object + * @return the underlying CTHyperlink object */ - protected CTHyperlink getCTHyperlink() { + public CTHyperlink getCTHyperlink() { return _ctHyperlink; } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 19ea45a3f..24cd2ba24 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -2501,7 +2501,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { comment.setColumn(cellReference.getCol()); } - protected void setCellHyperlink(XSSFHyperlink hyperlink) { + /** + * Register a hyperlink in the collection of hyperlinks on this sheet + * + * @param hyperlink the link to add + */ + @Internal + public void addHyperlink(XSSFHyperlink hyperlink) { hyperlinks.add(hyperlink); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/streaming/TestSXSSFHyperlink.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/streaming/TestSXSSFHyperlink.java new file mode 100755 index 000000000..ed8b91bac --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/streaming/TestSXSSFHyperlink.java @@ -0,0 +1,37 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.xssf.usermodel.streaming; + +import org.apache.poi.ss.usermodel.BaseTestCell; +import org.apache.poi.ss.usermodel.BaseTestHyperlink; +import org.apache.poi.xssf.SXSSFITestDataProvider; + +/** + * Test setting hyperlinks in SXSSF + * + * @author Yegor Kozlov + */ +public class TestSXSSFHyperlink extends BaseTestHyperlink { + + public TestSXSSFHyperlink() { + super(SXSSFITestDataProvider.instance); + } + +} \ No newline at end of file