@@ -957,14 +957,36 @@ type HyperlinkOpts struct {
957
957
Tooltip * string
958
958
}
959
959
960
+ // removeHyperLink remove hyperlink for worksheet and delete relationships for
961
+ // the worksheet by given sheet name and cell reference. Note that if the cell
962
+ // in a range reference, the whole hyperlinks will be deleted.
963
+ func (f * File ) removeHyperLink (ws * xlsxWorksheet , sheet , cell string ) error {
964
+ for idx := 0 ; idx < len (ws .Hyperlinks .Hyperlink ); idx ++ {
965
+ link := ws .Hyperlinks .Hyperlink [idx ]
966
+ ok , err := f .checkCellInRangeRef (cell , link .Ref )
967
+ if err != nil {
968
+ return err
969
+ }
970
+ if link .Ref == cell || ok {
971
+ ws .Hyperlinks .Hyperlink = append (ws .Hyperlinks .Hyperlink [:idx ], ws .Hyperlinks .Hyperlink [idx + 1 :]... )
972
+ idx --
973
+ f .deleteSheetRelationships (sheet , link .RID )
974
+ }
975
+ }
976
+ if len (ws .Hyperlinks .Hyperlink ) == 0 {
977
+ ws .Hyperlinks = nil
978
+ }
979
+ return nil
980
+ }
981
+
960
982
// SetCellHyperLink provides a function to set cell hyperlink by given
961
- // worksheet name and link URL address. LinkType defines two types of
983
+ // worksheet name and link URL address. LinkType defines three types of
962
984
// hyperlink "External" for website or "Location" for moving to one of cell in
963
- // this workbook. Maximum limit hyperlinks in a worksheet is 65530. This
964
- // function is only used to set the hyperlink of the cell and doesn't affect
965
- // the value of the cell. If you need to set the value of the cell, please use
966
- // the other functions such as `SetCellStyle` or `SetSheetRow`. The below is
967
- // example for external link.
985
+ // this workbook or "None" for remove hyperlink . Maximum limit hyperlinks in a
986
+ // worksheet is 65530. This function is only used to set the hyperlink of the
987
+ // cell and doesn't affect the value of the cell. If you need to set the value
988
+ // of the cell, please use the other functions such as `SetCellStyle` or
989
+ // `SetSheetRow`. The below is example for external link.
968
990
//
969
991
// display, tooltip := "https://github.com/xuri/excelize", "Excelize on GitHub"
970
992
// if err := f.SetCellHyperLink("Sheet1", "A3",
@@ -1032,6 +1054,8 @@ func (f *File) SetCellHyperLink(sheet, cell, link, linkType string, opts ...Hype
1032
1054
Ref : cell ,
1033
1055
Location : link ,
1034
1056
}
1057
+ case "None" :
1058
+ return f .removeHyperLink (ws , sheet , cell )
1035
1059
default :
1036
1060
return newInvalidLinkTypeError (linkType )
1037
1061
}
0 commit comments