poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1753009 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/streaming/ ooxml/java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/ss/usermodel/
Date Sun, 17 Jul 2016 04:41:20 GMT
Author: onealj
Date: Sun Jul 17 04:41:20 2016
New Revision: 1753009

URL: http://svn.apache.org/viewvc?rev=1753009&view=rev
Log:
bug 59872: add Sheet.getHyperlink(CellAddress)

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1753009&r1=1753008&r2=1753009&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Sun Jul 17 04:41:20 2016
@@ -2216,6 +2216,17 @@ public final class HSSFSheet implements
     }
     
     /**
+     * Get a Hyperlink in this sheet located in a cell specified by {code addr}
+     *
+     * @param addr The address of the cell containing the hyperlink
+     * @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns
{@code null}
+     */
+    @Override
+    public HSSFHyperlink getHyperlink(CellAddress addr) {
+        return getHyperlink(addr.getRow(), addr.getColumn());
+    }
+    
+    /**
      * Get a list of Hyperlinks in this sheet
      *
      * @return Hyperlinks for the sheet

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java?rev=1753009&r1=1753008&r2=1753009&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Sheet.java Sun Jul 17 04:41:20 2016
@@ -1159,6 +1159,14 @@ public interface Sheet extends Iterable<
     public Hyperlink getHyperlink(int row, int column);
     
     /**
+     * Get a Hyperlink in this sheet located in a cell specified by {code addr}
+     *
+     * @param addr The address of the cell containing the hyperlink
+     * @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns
{@code null}
+     */
+    public Hyperlink getHyperlink(CellAddress addr);
+    
+    /**
      * Get a list of Hyperlinks in this sheet
      *
      * @return Hyperlinks for the sheet

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1753009&r1=1753008&r2=1753009&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Sun Jul 17 04:41:20
2016
@@ -1666,6 +1666,17 @@ public class SXSSFSheet implements Sheet
     }
     
     /**
+     * Get a Hyperlink in this sheet located in a cell specified by {code addr}
+     *
+     * @param addr The address of the cell containing the hyperlink
+     * @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns
{@code null}
+     */
+    @Override
+    public XSSFHyperlink getHyperlink(CellAddress addr) {
+        return _sh.getHyperlink(addr);
+    }
+    
+    /**
      * Get a list of Hyperlinks in this sheet
      *
      * @return Hyperlinks for the sheet

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1753009&r1=1753008&r2=1753009&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sun Jul 17 04:41:20
2016
@@ -806,7 +806,18 @@ public class XSSFSheet extends POIXMLDoc
      */
     @Override
     public XSSFHyperlink getHyperlink(int row, int column) {
-        String ref = new CellReference(row, column).formatAsString();
+        return getHyperlink(new CellAddress(row, column));
+    }
+    
+    /**
+     * Get a Hyperlink in this sheet located in a cell specified by {code addr}
+     *
+     * @param addr The address of the cell containing the hyperlink
+     * @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns
{@code null}
+     */
+    @Override
+    public XSSFHyperlink getHyperlink(CellAddress addr) {
+        String ref = addr.formatAsString();
         for(XSSFHyperlink hyperlink : hyperlinks) {
             if(hyperlink.getCellRef().equals(ref)) {
                 return hyperlink;

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java?rev=1753009&r1=1753008&r2=1753009&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java Sun Jul 17 04:41:20
2016
@@ -1208,6 +1208,27 @@ public abstract class BaseTestSheet {
         workbook.close();
         wb.close();
     }
+    
+    @Test
+    public void getHyperlink() throws IOException {
+        Workbook workbook = _testDataProvider.createWorkbook();
+        Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
+        hyperlink.setAddress("https://poi.apache.org/");
+        
+        Sheet sheet = workbook.createSheet();
+        Cell cell = sheet.createRow(5).createCell(1);
+        
+        assertEquals("list size before add", 0, sheet.getHyperlinkList().size());
+        cell.setHyperlink(hyperlink);
+        assertEquals("list size after add", 1, sheet.getHyperlinkList().size());
+        
+        assertEquals("list", hyperlink, sheet.getHyperlinkList().get(0));
+        assertEquals("row, col", hyperlink, sheet.getHyperlink(5, 1));
+        assertEquals("addr", hyperlink, sheet.getHyperlink(new CellAddress("B4")));
+        assertEquals("no hyperlink at A1", null, sheet.getHyperlink(CellAddress.A1));
+        
+        workbook.close();
+    }
 
 
     @Test



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


Mime
View raw message