From 773d4afa32a55349a7b178c4c76d182f9ed0221f Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 1 May 2022 12:28:36 +0800 Subject: This closes #1217, support update cell hyperlink Ref #1129, make `SetRowStyle` overwrite style of the cells --- cell.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'cell.go') 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. -- cgit v1.2.1