summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/cell.go b/cell.go
index 1d6ed84..70832ce 100644
--- a/cell.go
+++ b/cell.go
@@ -715,10 +715,17 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string, opts ...Hype
}
var linkData xlsxHyperlink
-
+ idx := -1
if ws.Hyperlinks == nil {
ws.Hyperlinks = new(xlsxHyperlinks)
}
+ for i, hyperlink := range ws.Hyperlinks.Hyperlink {
+ if hyperlink.Ref == axis {
+ idx = i
+ linkData = hyperlink
+ break
+ }
+ }
if len(ws.Hyperlinks.Hyperlink) > TotalSheetHyperlinks {
return ErrTotalSheetHyperlinks
@@ -726,12 +733,12 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string, opts ...Hype
switch linkType {
case "External":
+ sheetPath := f.sheetMap[trimSheetName(sheet)]
+ sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(sheetPath, "xl/worksheets/") + ".rels"
+ rID := f.setRels(linkData.RID, sheetRels, SourceRelationshipHyperLink, link, linkType)
linkData = xlsxHyperlink{
Ref: axis,
}
- sheetPath := f.sheetMap[trimSheetName(sheet)]
- sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(sheetPath, "xl/worksheets/") + ".rels"
- rID := f.addRels(sheetRels, SourceRelationshipHyperLink, link, linkType)
linkData.RID = "rId" + strconv.Itoa(rID)
f.addSheetNameSpace(sheet, SourceRelationship)
case "Location":
@@ -751,9 +758,12 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string, opts ...Hype
linkData.Tooltip = *o.Tooltip
}
}
-
- ws.Hyperlinks.Hyperlink = append(ws.Hyperlinks.Hyperlink, linkData)
- return nil
+ if idx == -1 {
+ ws.Hyperlinks.Hyperlink = append(ws.Hyperlinks.Hyperlink, linkData)
+ return err
+ }
+ ws.Hyperlinks.Hyperlink[idx] = linkData
+ return err
}
// getCellRichText returns rich text of cell by given string item.