diff options
author | xuri <xuri.me@gmail.com> | 2022-05-01 12:28:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-01 12:28:36 +0800 |
commit | 773d4afa32a55349a7b178c4c76d182f9ed0221f (patch) | |
tree | d176338fc1c550dab8201180f822dbf6dfad074d /cell.go | |
parent | 856ee57c4019b4478da0f6cb3010ae636914a6be (diff) |
This closes #1217, support update cell hyperlink
Ref #1129, make `SetRowStyle` overwrite style of the cells
Diffstat (limited to 'cell.go')
-rw-r--r-- | cell.go | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -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. |