diff options
author | Ri Xu <xuri.me@gmail.com> | 2017-07-30 15:46:04 +0800 |
---|---|---|
committer | Ri Xu <xuri.me@gmail.com> | 2017-07-30 15:46:04 +0800 |
commit | 308776e350334a8daddcf5f502ee7547f01cc64c (patch) | |
tree | 8cc7850e18b2d5dae995c213d27bcb0fab7794c9 /cell.go | |
parent | 1d54bd4df6542edcce1f820c0b29e2cc00f10563 (diff) |
Optimize code, go test and godoc updated.
Diffstat (limited to 'cell.go')
-rw-r--r-- | cell.go | 36 |
1 files changed, 16 insertions, 20 deletions
@@ -215,34 +215,30 @@ func (f *File) SetCellFormula(sheet, axis, formula string) { // style, _ := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`) // xlsx.SetCellStyle("Sheet1", "A3", "A3", style) // -// A this is another example for "Location" +// 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) - var hyperlink xlsxHyperlink + linkTypes := map[string]xlsxHyperlink{ + "External": {}, + "Location": {Location: link}, + } + hyperlink, ok := linkTypes[linkType] + if !ok || axis == "" { + return + } + hyperlink.Ref = axis 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, - } + rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, linkType) + hyperlink.RID = "rId" + strconv.Itoa(rID) } - 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{} - hyperlinks.Hyperlink = append(hyperlinks.Hyperlink, hyperlink) - xlsx.Hyperlinks = &hyperlinks + if xlsx.Hyperlinks == nil { + xlsx.Hyperlinks = &xlsxHyperlinks{} } + xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, hyperlink) } // MergeCell provides function to merge cells by given coordinate area and sheet |