summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2017-08-08 20:08:54 +0800
committerRi Xu <xuri.me@gmail.com>2017-08-08 20:08:54 +0800
commita8cf38ebd5537b678a3747cd246fd1c511c73331 (patch)
tree0600555d920580430a79bce38fae144e6ce396f5
parent5cf3725f026d2a1dbf3208d575ade996cfd7e7ec (diff)
- New function `GetCellHyperLink()` added, relate issue #98;
- go test added
-rw-r--r--cell.go28
-rw-r--r--excelize_test.go15
2 files changed, 43 insertions, 0 deletions
diff --git a/cell.go b/cell.go
index 5d9557c..b182e2b 100644
--- a/cell.go
+++ b/cell.go
@@ -241,6 +241,34 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) {
xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, hyperlink)
}
+// GetCellHyperLink provides function to get cell hyperlink by given sheet index
+// and axis. Boolean type value link will be ture if the cell has a hyperlink
+// and the target is the address of the hyperlink. Otherwise, the value of link
+// will be false and the value of the target will be a blank string. For example
+// get hyperlink of Sheet1!H6:
+//
+// link, target := xlsx.GetCellHyperLink("Sheet1", "H6")
+//
+func (f *File) GetCellHyperLink(sheet, axis string) (bool, string) {
+ var link bool
+ var target string
+ xlsx := f.workSheetReader(sheet)
+ axis = f.mergeCellsParser(xlsx, axis)
+ if xlsx.Hyperlinks == nil || axis == "" {
+ return link, target
+ }
+ for _, h := range xlsx.Hyperlinks.Hyperlink {
+ if h.Ref == axis {
+ link = true
+ target = h.Location
+ if h.RID != "" {
+ target = f.getSheetRelationshipsTargetByID(sheet, h.RID)
+ }
+ }
+ }
+ return link, target
+}
+
// MergeCell provides function to merge cells by given coordinate area and sheet
// name. For example create a merged cell of D3:E9 on Sheet1:
//
diff --git a/excelize_test.go b/excelize_test.go
index 89c8ce9..2798319 100644
--- a/excelize_test.go
+++ b/excelize_test.go
@@ -223,6 +223,21 @@ func TestSetCellHyperLink(t *testing.T) {
}
}
+func TestGetCellHyperLink(t *testing.T) {
+ xlsx, err := OpenFile("./test/Workbook1.xlsx")
+ if err != nil {
+ t.Log(err)
+ }
+ link, target := xlsx.GetCellHyperLink("Sheet1", "")
+ t.Log(link, target)
+ link, target = xlsx.GetCellHyperLink("Sheet1", "B19")
+ t.Log(link, target)
+ link, target = xlsx.GetCellHyperLink("Sheet2", "D6")
+ t.Log(link, target)
+ link, target = xlsx.GetCellHyperLink("Sheet3", "H3")
+ t.Log(link, target)
+}
+
func TestSetCellFormula(t *testing.T) {
xlsx, err := OpenFile("./test/Workbook1.xlsx")
if err != nil {