@@ -1374,6 +1374,26 @@ var (
13741374 "5Quarters" : cfvo5 ,
13751375 "5Rating" : cfvo5 ,
13761376 }
1377+
1378+ // cfvo3 defined the icon set conditional formatting rules.
1379+ x14cfvo3 = & xlsxX14CfRule {IconSet : & xlsx14IconSet {Cfvo : []* xlsx14Cfvo {
1380+ {Type : "percent" , Val : "0" },
1381+ {Type : "percent" , Val : "33" },
1382+ {Type : "percent" , Val : "67" },
1383+ }}}
1384+ // cfvo5 defined the icon set conditional formatting rules.
1385+ x14cfvo5 = & xlsxX14CfRule {IconSet : & xlsx14IconSet {Cfvo : []* xlsx14Cfvo {
1386+ {Type : "percent" , Val : "0" },
1387+ {Type : "percent" , Val : "20" },
1388+ {Type : "percent" , Val : "40" },
1389+ {Type : "percent" , Val : "60" },
1390+ {Type : "percent" , Val : "80" },
1391+ }}}
1392+ condFmtNewIconSetPresets = map [string ]* xlsxX14CfRule {
1393+ "3Stars" : x14cfvo3 ,
1394+ "3Triangles" : x14cfvo3 ,
1395+ "5Boxes" : x14cfvo5 ,
1396+ }
13771397)
13781398
13791399// colorChoice returns a hex color code from the actual color values.
@@ -2764,17 +2784,20 @@ func (f *File) SetCellStyle(sheet, topLeftCell, bottomRightCell string, styleID
27642784// 3ArrowsGray
27652785// 3Flags
27662786// 3Signs
2787+ // 3Stars
27672788// 3Symbols
27682789// 3Symbols2
27692790// 3TrafficLights1
27702791// 3TrafficLights2
2792+ // 3Triangles
27712793// 4Arrows
27722794// 4ArrowsGray
27732795// 4Rating
27742796// 4RedToBlack
27752797// 4TrafficLights
27762798// 5Arrows
27772799// 5ArrowsGray
2800+ // 5Boxes
27782801// 5Quarters
27792802// 5Rating
27802803//
@@ -2802,6 +2825,7 @@ func (f *File) SetConditionalFormat(sheet, rangeRef string, opts []ConditionalFo
28022825 }
28032826 var (
28042827 cfRule []* xlsxCfRule
2828+ x14CfRule []* xlsxX14CfRule
28052829 noCriteriaTypes = []string {
28062830 "containsBlanks" ,
28072831 "notContainsBlanks" ,
@@ -2825,16 +2849,15 @@ func (f *File) SetConditionalFormat(sheet, rangeRef string, opts []ConditionalFo
28252849 priority := rules + i
28262850 rule , x14rule := drawFunc (priority , ct , mastCell ,
28272851 fmt .Sprintf ("{00000000-0000-0000-%04X-%012X}" , f .getSheetID (sheet ), priority ), & opt )
2828- if rule == nil {
2852+ if rule == nil && x14rule == nil {
28292853 return ErrParameterInvalid
28302854 }
28312855 if x14rule != nil {
2832- if err = f . appendCfRule ( ws , x14rule ); err != nil {
2833- return err
2834- }
2835- f . addSheetNameSpace ( sheet , NameSpaceSpreadSheetX14 )
2856+ x14CfRule = append ( x14CfRule , x14rule )
2857+ }
2858+ if rule != nil {
2859+ cfRule = append ( cfRule , rule )
28362860 }
2837- cfRule = append (cfRule , rule )
28382861 continue
28392862 }
28402863 }
@@ -2843,10 +2866,19 @@ func (f *File) SetConditionalFormat(sheet, rangeRef string, opts []ConditionalFo
28432866 return ErrParameterInvalid
28442867 }
28452868
2846- ws .ConditionalFormatting = append (ws .ConditionalFormatting , & xlsxConditionalFormatting {
2847- SQRef : SQRef ,
2848- CfRule : cfRule ,
2849- })
2869+ if len (cfRule ) > 0 {
2870+ ws .ConditionalFormatting = append (ws .ConditionalFormatting , & xlsxConditionalFormatting {
2871+ SQRef : SQRef ,
2872+ CfRule : cfRule ,
2873+ })
2874+ }
2875+
2876+ if len (x14CfRule ) > 0 {
2877+ if err = f .appendCfRule (ws , x14CfRule , SQRef ); err != nil {
2878+ return err
2879+ }
2880+ f .addSheetNameSpace (sheet , NameSpaceSpreadSheetX14 )
2881+ }
28502882 return err
28512883}
28522884
@@ -2892,7 +2924,7 @@ func prepareConditionalFormatRange(rangeRef string) (string, string, error) {
28922924}
28932925
28942926// appendCfRule provides a function to append rules to conditional formatting.
2895- func (f * File ) appendCfRule (ws * xlsxWorksheet , rule * xlsxX14CfRule ) error {
2927+ func (f * File ) appendCfRule (ws * xlsxWorksheet , rules [] * xlsxX14CfRule , SQRef string ) error {
28962928 var (
28972929 err error
28982930 idx int
@@ -2904,7 +2936,7 @@ func (f *File) appendCfRule(ws *xlsxWorksheet, rule *xlsxX14CfRule) error {
29042936 condFmtBytes , condFmtsBytes , extLstBytes []byte
29052937 )
29062938 condFmtBytes , _ = xml .Marshal ([]* xlsxX14ConditionalFormatting {
2907- {XMLNSXM : NameSpaceSpreadSheetExcel2006Main .Value , CfRule : [] * xlsxX14CfRule { rule } },
2939+ {XMLNSXM : NameSpaceSpreadSheetExcel2006Main .Value , CfRule : rules , SQRef : SQRef },
29082940 })
29092941 if ws .ExtLst != nil { // append mode ext
29102942 if err = f .xmlNewDecoder (strings .NewReader ("<extLst>" + ws .ExtLst .Ext + "</extLst>" )).
@@ -3467,7 +3499,16 @@ func drawCondFmtNoBlanks(p int, ct, ref, GUID string, format *ConditionalFormatO
34673499func drawCondFmtIconSet (p int , ct , ref , GUID string , format * ConditionalFormatOptions ) (* xlsxCfRule , * xlsxX14CfRule ) {
34683500 cfRule , ok := condFmtIconSetPresets [format .IconStyle ]
34693501 if ! ok {
3470- return nil , nil
3502+ x14CfRule , ok := condFmtNewIconSetPresets [format .IconStyle ]
3503+ if ! ok {
3504+ return nil , nil
3505+ }
3506+ x14CfRule .Priority = p + 1
3507+ x14CfRule .IconSet .IconSet = format .IconStyle
3508+ x14CfRule .IconSet .Reverse = format .ReverseIcons
3509+ x14CfRule .IconSet .ShowValue = boolPtr (! format .IconsOnly )
3510+ x14CfRule .Type = validType [format .Type ]
3511+ return nil , x14CfRule
34713512 }
34723513 cfRule .Priority = p + 1
34733514 cfRule .IconSet .IconSet = format .IconStyle
0 commit comments