@@ -215,34 +215,30 @@ func (f *File) SetCellFormula(sheet, axis, formula string) {
215
215
// style, _ := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
216
216
// xlsx.SetCellStyle("Sheet1", "A3", "A3", style)
217
217
//
218
- // A this is another example for "Location"
218
+ // A this is another example for "Location":
219
219
//
220
220
// xlsx.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
221
+ //
221
222
func (f * File ) SetCellHyperLink (sheet , axis , link , linkType string ) {
222
223
xlsx := f .workSheetReader (sheet )
223
224
axis = f .mergeCellsParser (xlsx , axis )
224
- var hyperlink xlsxHyperlink
225
+ linkTypes := map [string ]xlsxHyperlink {
226
+ "External" : {},
227
+ "Location" : {Location : link },
228
+ }
229
+ hyperlink , ok := linkTypes [linkType ]
230
+ if ! ok || axis == "" {
231
+ return
232
+ }
233
+ hyperlink .Ref = axis
225
234
if linkType == "External" {
226
- rID := f .addSheetRelationships (sheet , SourceRelationshipHyperLink , link , "External" )
227
- hyperlink = xlsxHyperlink {
228
- Ref : axis ,
229
- RID : "rId" + strconv .Itoa (rID ),
230
- }
231
- } else if linkType == "Location" {
232
- hyperlink = xlsxHyperlink {
233
- Ref : axis ,
234
- Location : link ,
235
- }
235
+ rID := f .addSheetRelationships (sheet , SourceRelationshipHyperLink , link , linkType )
236
+ hyperlink .RID = "rId" + strconv .Itoa (rID )
236
237
}
237
- if hyperlink .Ref == "" {
238
- panic ("linkType only support External and Location now" )
239
- } else if xlsx .Hyperlinks != nil {
240
- xlsx .Hyperlinks .Hyperlink = append (xlsx .Hyperlinks .Hyperlink , hyperlink )
241
- } else {
242
- hyperlinks := xlsxHyperlinks {}
243
- hyperlinks .Hyperlink = append (hyperlinks .Hyperlink , hyperlink )
244
- xlsx .Hyperlinks = & hyperlinks
238
+ if xlsx .Hyperlinks == nil {
239
+ xlsx .Hyperlinks = & xlsxHyperlinks {}
245
240
}
241
+ xlsx .Hyperlinks .Hyperlink = append (xlsx .Hyperlinks .Hyperlink , hyperlink )
246
242
}
247
243
248
244
// MergeCell provides function to merge cells by given coordinate area and sheet
0 commit comments