|
|
@ -215,34 +215,30 @@ func (f *File) SetCellFormula(sheet, axis, formula string) {
|
|
|
|
// style, _ := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
|
|
|
|
// style, _ := xlsx.NewStyle(`{"font":{"color":"#1265BE","underline":"single"}}`)
|
|
|
|
// xlsx.SetCellStyle("Sheet1", "A3", "A3", style)
|
|
|
|
// 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")
|
|
|
|
// xlsx.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location")
|
|
|
|
|
|
|
|
//
|
|
|
|
func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) {
|
|
|
|
func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) {
|
|
|
|
xlsx := f.workSheetReader(sheet)
|
|
|
|
xlsx := f.workSheetReader(sheet)
|
|
|
|
axis = f.mergeCellsParser(xlsx, axis)
|
|
|
|
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" {
|
|
|
|
if linkType == "External" {
|
|
|
|
rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, "External")
|
|
|
|
rID := f.addSheetRelationships(sheet, SourceRelationshipHyperLink, link, linkType)
|
|
|
|
hyperlink = xlsxHyperlink{
|
|
|
|
hyperlink.RID = "rId" + strconv.Itoa(rID)
|
|
|
|
Ref: axis,
|
|
|
|
|
|
|
|
RID: "rId" + strconv.Itoa(rID),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if linkType == "Location" {
|
|
|
|
|
|
|
|
hyperlink = xlsxHyperlink{
|
|
|
|
|
|
|
|
Ref: axis,
|
|
|
|
|
|
|
|
Location: link,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if hyperlink.Ref == "" {
|
|
|
|
if xlsx.Hyperlinks == nil {
|
|
|
|
panic("linkType only support External and Location now")
|
|
|
|
xlsx.Hyperlinks = &xlsxHyperlinks{}
|
|
|
|
} 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
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xlsx.Hyperlinks.Hyperlink = append(xlsx.Hyperlinks.Hyperlink, hyperlink)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MergeCell provides function to merge cells by given coordinate area and sheet
|
|
|
|
// MergeCell provides function to merge cells by given coordinate area and sheet
|
|
|
|