- New function `GetCellHyperLink()` added, relate issue #98;

- go test added
This commit is contained in:
Ri Xu 2017-08-08 20:08:54 +08:00
parent 5cf3725f02
commit a8cf38ebd5
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 43 additions and 0 deletions

28
cell.go
View File

@ -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:
//

View File

@ -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 {