summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2017-07-30 15:05:40 +0800
committerGitHub <noreply@github.com>2017-07-30 15:05:40 +0800
commit1d54bd4df6542edcce1f820c0b29e2cc00f10563 (patch)
treec89f9c4add1a4756fef9fa338d569138abe3204a /cell.go
parentbbed2f6dc9d73bb6ab6e0c7923c18acdafa13cd5 (diff)
parent5a4870d1cf50efe99c6ba8b62a4f0071819ce13f (diff)
Merge pull request #90 from DeveloperBean/master
Add extra argument "Linktype" to SetCellHyperLink
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/cell.go b/cell.go
index 652dc9f..6125583 100644
--- a/cell.go
+++ b/cell.go
@@ -206,23 +206,37 @@ func (f *File) SetCellFormula(sheet, axis, formula string) {
}
// SetCellHyperLink provides function to set cell hyperlink by given sheet index
-// and link URL address. Only support external link currently. For example: add
-// hyperLink for Sheet1!A3:
+// and link URL address. LinkType defines two types of hyperlink "External" for
+// web site or "Location" for moving to one of cell in this workbook. The below
+// is example for external link.
//
-// xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/xuri/excelize")
+// xlsx.SetCellHyperLink("Sheet1", "A3", "https://github.com/xuri/excelize", "External")
// // Set underline and font color style for the cell.
// style, _ := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
// xlsx.SetCellStyle("Sheet1", "A3", "A3", style)
//
-func (f *File) SetCellHyperLink(sheet, axis, link string) {
+// A this is another example for "Location"
+//
+// xlsx.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
+func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) {
xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis)
- rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, "External")
- hyperlink := xlsxHyperlink{
- Ref: axis,
- RID: "rId" + strconv.Itoa(rID),
+ var hyperlink xlsxHyperlink
+ if linkType == "External" {
+ rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, "External")
+ hyperlink = xlsxHyperlink{
+ Ref: axis,
+ RID: "rId" + strconv.Itoa(rID),
+ }
+ } else if linkType == "Location" {
+ hyperlink = xlsxHyperlink{
+ Ref: axis,
+ Location: link,
+ }
}
- if xlsx.Hyperlinks != nil {
+ if hyperlink.Ref == "" {
+ panic("linkType only support External and Location now")
+ } else if xlsx.Hyperlinks != nil {
xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, hyperlink)
} else {
hyperlinks := xlsxHyperlinks{}