return null;
}
+ /**
+ * 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
*
*/
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 _sh.getHyperlink(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) {
+ return _sh.getHyperlink(addr);
+ }
+
/**
* Get a list of Hyperlinks in this sheet
*
*/
@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;
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