diff options
author | Nick Burch <nick@apache.org> | 2014-11-08 13:46:30 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2014-11-08 13:46:30 +0000 |
commit | 9b9b4b8cf47ee1af88c37250a9905fa8b70502a4 (patch) | |
tree | 21fd62d57a442c0c245b1b72e9224a12c6643ea6 /src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | |
parent | efb42dc897d53e1e93cc5d15dbc853ebaf603f6c (diff) | |
download | poi-9b9b4b8cf47ee1af88c37250a9905fa8b70502a4.tar.gz poi-9b9b4b8cf47ee1af88c37250a9905fa8b70502a4.zip |
Patch from hishidama to add Cell.removeHyperlink(). This closes #13 from github
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1637562 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hssf/usermodel/HSSFCell.java')
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index c66cdd3d13..e5de299a04 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -1062,11 +1062,17 @@ public class HSSFCell implements Cell { } /** - * Assign a hyperlink to this cell + * Assign a hyperlink to this cell. If the supplied hyperlink is null, the + * hyperlink for this cell will be removed. * * @param hyperlink hyperlink associated with this cell */ public void setHyperlink(Hyperlink hyperlink){ + if (hyperlink == null) { + removeHyperlink(); + return; + } + HSSFHyperlink link = (HSSFHyperlink)hyperlink; link.setFirstRow(_record.getRow()); @@ -1091,6 +1097,23 @@ public class HSSFCell implements Cell { int eofLoc = records.size() - 1; records.add( eofLoc, link.record ); } + + /** + * Removes the hyperlink for this cell, if there is one. + */ + public void removeHyperlink() { + for (Iterator<RecordBase> it = _sheet.getSheet().getRecords().iterator(); it.hasNext();) { + RecordBase rec = it.next(); + if (rec instanceof HyperlinkRecord) { + HyperlinkRecord link = (HyperlinkRecord) rec; + if (link.getFirstColumn() == _record.getColumn() && link.getFirstRow() == _record.getRow()) { + it.remove(); + return; + } + } + } + } + /** * Only valid for formula cells * @return one of ({@link #CELL_TYPE_NUMERIC}, {@link #CELL_TYPE_STRING}, |