Skip to content

Commit bb8e5da

Browse files
committed
This closes #1769 and closes #1770, support multiple conditional formats rules
- Update the unit tests
1 parent 8831afc commit bb8e5da

File tree

3 files changed

+122
-64
lines changed

3 files changed

+122
-64
lines changed

styles.go

Lines changed: 99 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,25 +1161,61 @@ var (
11611161
"iconSet": drawCondFmtIconSet,
11621162
}
11631163
// extractContFmtFunc defines functions to get conditional formats.
1164-
extractContFmtFunc = map[string]func(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions{
1165-
"cellIs": extractCondFmtCellIs,
1166-
"timePeriod": extractCondFmtTimePeriod,
1167-
"containsText": extractCondFmtText,
1168-
"notContainsText": extractCondFmtText,
1169-
"beginsWith": extractCondFmtText,
1170-
"endsWith": extractCondFmtText,
1171-
"top10": extractCondFmtTop10,
1172-
"aboveAverage": extractCondFmtAboveAverage,
1173-
"duplicateValues": extractCondFmtDuplicateUniqueValues,
1174-
"uniqueValues": extractCondFmtDuplicateUniqueValues,
1175-
"containsBlanks": extractCondFmtBlanks,
1176-
"notContainsBlanks": extractCondFmtNoBlanks,
1177-
"containsErrors": extractCondFmtErrors,
1178-
"notContainsErrors": extractCondFmtNoErrors,
1179-
"colorScale": extractCondFmtColorScale,
1180-
"dataBar": extractCondFmtDataBar,
1181-
"expression": extractCondFmtExp,
1182-
"iconSet": extractCondFmtIconSet,
1164+
extractContFmtFunc = map[string]func(*File, *xlsxCfRule, *xlsxExtLst) ConditionalFormatOptions{
1165+
"cellIs": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1166+
return f.extractCondFmtCellIs(c, extLst)
1167+
},
1168+
"timePeriod": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1169+
return f.extractCondFmtTimePeriod(c, extLst)
1170+
},
1171+
"containsText": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1172+
return f.extractCondFmtText(c, extLst)
1173+
},
1174+
"notContainsText": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1175+
return f.extractCondFmtText(c, extLst)
1176+
},
1177+
"beginsWith": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1178+
return f.extractCondFmtText(c, extLst)
1179+
},
1180+
"endsWith": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1181+
return f.extractCondFmtText(c, extLst)
1182+
},
1183+
"top10": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1184+
return f.extractCondFmtTop10(c, extLst)
1185+
},
1186+
"aboveAverage": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1187+
return f.extractCondFmtAboveAverage(c, extLst)
1188+
},
1189+
"duplicateValues": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1190+
return f.extractCondFmtDuplicateUniqueValues(c, extLst)
1191+
},
1192+
"uniqueValues": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1193+
return f.extractCondFmtDuplicateUniqueValues(c, extLst)
1194+
},
1195+
"containsBlanks": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1196+
return f.extractCondFmtBlanks(c, extLst)
1197+
},
1198+
"notContainsBlanks": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1199+
return f.extractCondFmtNoBlanks(c, extLst)
1200+
},
1201+
"containsErrors": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1202+
return f.extractCondFmtErrors(c, extLst)
1203+
},
1204+
"notContainsErrors": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1205+
return f.extractCondFmtNoErrors(c, extLst)
1206+
},
1207+
"colorScale": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1208+
return f.extractCondFmtColorScale(c, extLst)
1209+
},
1210+
"dataBar": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1211+
return f.extractCondFmtDataBar(c, extLst)
1212+
},
1213+
"expression": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1214+
return f.extractCondFmtExp(c, extLst)
1215+
},
1216+
"iconSet": func(f *File, c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
1217+
return f.extractCondFmtIconSet(c, extLst)
1218+
},
11831219
}
11841220
// validType defined the list of valid validation types.
11851221
validType = map[string]string{
@@ -2713,7 +2749,6 @@ func (f *File) SetConditionalFormat(sheet, rangeRef string, opts []ConditionalFo
27132749
rules += len(cf.CfRule)
27142750
}
27152751
var (
2716-
GUID = fmt.Sprintf("{00000000-0000-0000-%04X-%012X}", f.getSheetID(sheet), rules)
27172752
cfRule []*xlsxCfRule
27182753
noCriteriaTypes = []string{
27192754
"containsBlanks",
@@ -2735,7 +2770,8 @@ func (f *File) SetConditionalFormat(sheet, rangeRef string, opts []ConditionalFo
27352770
if ok || inStrSlice(noCriteriaTypes, vt, true) != -1 {
27362771
drawFunc, ok := drawContFmtFunc[vt]
27372772
if ok {
2738-
rule, x14rule := drawFunc(p, ct, strings.Split(rangeRef, ":")[0], GUID, &v)
2773+
rule, x14rule := drawFunc(p, ct, strings.Split(rangeRef, ":")[0],
2774+
fmt.Sprintf("{00000000-0000-0000-%04X-%012X}", f.getSheetID(sheet), rules+p), &v)
27392775
if rule == nil {
27402776
return ErrParameterInvalid
27412777
}
@@ -2813,7 +2849,7 @@ func (f *File) appendCfRule(ws *xlsxWorksheet, rule *xlsxX14CfRule) error {
28132849
// extractCondFmtCellIs provides a function to extract conditional format
28142850
// settings for cell value (include between, not between, equal, not equal,
28152851
// greater than and less than) by given conditional formatting rule.
2816-
func extractCondFmtCellIs(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2852+
func (f *File) extractCondFmtCellIs(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
28172853
format := ConditionalFormatOptions{StopIfTrue: c.StopIfTrue, Type: "cell", Criteria: operatorType[c.Operator]}
28182854
if c.DxfID != nil {
28192855
format.Format = *c.DxfID
@@ -2828,7 +2864,7 @@ func extractCondFmtCellIs(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOp
28282864

28292865
// extractCondFmtTimePeriod provides a function to extract conditional format
28302866
// settings for time period by given conditional formatting rule.
2831-
func extractCondFmtTimePeriod(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2867+
func (f *File) extractCondFmtTimePeriod(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
28322868
format := ConditionalFormatOptions{StopIfTrue: c.StopIfTrue, Type: "time_period", Criteria: operatorType[c.Operator]}
28332869
if c.DxfID != nil {
28342870
format.Format = *c.DxfID
@@ -2838,7 +2874,7 @@ func extractCondFmtTimePeriod(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalForm
28382874

28392875
// extractCondFmtText provides a function to extract conditional format
28402876
// settings for text cell values by given conditional formatting rule.
2841-
func extractCondFmtText(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2877+
func (f *File) extractCondFmtText(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
28422878
format := ConditionalFormatOptions{StopIfTrue: c.StopIfTrue, Type: "text", Criteria: operatorType[c.Operator], Value: c.Text}
28432879
if c.DxfID != nil {
28442880
format.Format = *c.DxfID
@@ -2849,7 +2885,7 @@ func extractCondFmtText(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOpti
28492885
// extractCondFmtTop10 provides a function to extract conditional format
28502886
// settings for top N (default is top 10) by given conditional formatting
28512887
// rule.
2852-
func extractCondFmtTop10(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2888+
func (f *File) extractCondFmtTop10(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
28532889
format := ConditionalFormatOptions{
28542890
StopIfTrue: c.StopIfTrue,
28552891
Type: "top",
@@ -2869,7 +2905,7 @@ func extractCondFmtTop10(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOpt
28692905
// extractCondFmtAboveAverage provides a function to extract conditional format
28702906
// settings for above average and below average by given conditional formatting
28712907
// rule.
2872-
func extractCondFmtAboveAverage(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2908+
func (f *File) extractCondFmtAboveAverage(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
28732909
format := ConditionalFormatOptions{
28742910
StopIfTrue: c.StopIfTrue,
28752911
Type: "average",
@@ -2887,7 +2923,7 @@ func extractCondFmtAboveAverage(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFo
28872923
// extractCondFmtDuplicateUniqueValues provides a function to extract
28882924
// conditional format settings for duplicate and unique values by given
28892925
// conditional formatting rule.
2890-
func extractCondFmtDuplicateUniqueValues(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2926+
func (f *File) extractCondFmtDuplicateUniqueValues(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
28912927
format := ConditionalFormatOptions{
28922928
StopIfTrue: c.StopIfTrue,
28932929
Type: map[string]string{
@@ -2904,7 +2940,7 @@ func extractCondFmtDuplicateUniqueValues(c *xlsxCfRule, extLst *xlsxExtLst) Cond
29042940

29052941
// extractCondFmtBlanks provides a function to extract conditional format
29062942
// settings for blank cells by given conditional formatting rule.
2907-
func extractCondFmtBlanks(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2943+
func (f *File) extractCondFmtBlanks(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
29082944
format := ConditionalFormatOptions{
29092945
StopIfTrue: c.StopIfTrue,
29102946
Type: "blanks",
@@ -2917,7 +2953,7 @@ func extractCondFmtBlanks(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOp
29172953

29182954
// extractCondFmtNoBlanks provides a function to extract conditional format
29192955
// settings for no blank cells by given conditional formatting rule.
2920-
func extractCondFmtNoBlanks(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2956+
func (f *File) extractCondFmtNoBlanks(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
29212957
format := ConditionalFormatOptions{
29222958
StopIfTrue: c.StopIfTrue,
29232959
Type: "no_blanks",
@@ -2930,7 +2966,7 @@ func extractCondFmtNoBlanks(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormat
29302966

29312967
// extractCondFmtErrors provides a function to extract conditional format
29322968
// settings for cells with errors by given conditional formatting rule.
2933-
func extractCondFmtErrors(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2969+
func (f *File) extractCondFmtErrors(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
29342970
format := ConditionalFormatOptions{
29352971
StopIfTrue: c.StopIfTrue,
29362972
Type: "errors",
@@ -2943,7 +2979,7 @@ func extractCondFmtErrors(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOp
29432979

29442980
// extractCondFmtNoErrors provides a function to extract conditional format
29452981
// settings for cells without errors by given conditional formatting rule.
2946-
func extractCondFmtNoErrors(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2982+
func (f *File) extractCondFmtNoErrors(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
29472983
format := ConditionalFormatOptions{
29482984
StopIfTrue: c.StopIfTrue,
29492985
Type: "no_errors",
@@ -2957,7 +2993,7 @@ func extractCondFmtNoErrors(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormat
29572993
// extractCondFmtColorScale provides a function to extract conditional format
29582994
// settings for color scale (include 2 color scale and 3 color scale) by given
29592995
// conditional formatting rule.
2960-
func extractCondFmtColorScale(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
2996+
func (f *File) extractCondFmtColorScale(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
29612997
format := ConditionalFormatOptions{StopIfTrue: c.StopIfTrue}
29622998
format.Type, format.Criteria = "2_color_scale", "="
29632999
values := len(c.ColorScale.Cfvo)
@@ -2967,66 +3003,68 @@ func extractCondFmtColorScale(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalForm
29673003
if c.ColorScale.Cfvo[0].Val != "0" {
29683004
format.MinValue = c.ColorScale.Cfvo[0].Val
29693005
}
2970-
format.MinColor = "#" + strings.TrimPrefix(strings.ToUpper(c.ColorScale.Color[0].RGB), "FF")
3006+
format.MinColor = "#" + f.getThemeColor(c.ColorScale.Color[0])
29713007
format.MaxType = c.ColorScale.Cfvo[1].Type
29723008
if c.ColorScale.Cfvo[1].Val != "0" {
29733009
format.MaxValue = c.ColorScale.Cfvo[1].Val
29743010
}
2975-
format.MaxColor = "#" + strings.TrimPrefix(strings.ToUpper(c.ColorScale.Color[1].RGB), "FF")
3011+
format.MaxColor = "#" + f.getThemeColor(c.ColorScale.Color[1])
29763012
}
29773013
if colors == 3 {
29783014
format.Type = "3_color_scale"
29793015
format.MidType = c.ColorScale.Cfvo[1].Type
29803016
if c.ColorScale.Cfvo[1].Val != "0" {
29813017
format.MidValue = c.ColorScale.Cfvo[1].Val
29823018
}
2983-
format.MidColor = "#" + strings.TrimPrefix(strings.ToUpper(c.ColorScale.Color[1].RGB), "FF")
3019+
format.MidColor = "#" + f.getThemeColor(c.ColorScale.Color[1])
29843020
format.MaxType = c.ColorScale.Cfvo[2].Type
29853021
if c.ColorScale.Cfvo[2].Val != "0" {
29863022
format.MaxValue = c.ColorScale.Cfvo[2].Val
29873023
}
2988-
format.MaxColor = "#" + strings.TrimPrefix(strings.ToUpper(c.ColorScale.Color[2].RGB), "FF")
3024+
format.MaxColor = "#" + f.getThemeColor(c.ColorScale.Color[2])
29893025
}
29903026
return format
29913027
}
29923028

3029+
// extractCondFmtDataBarRule provides a function to extract conditional format
3030+
// settings for data bar by given conditional formatting rule extension list.
3031+
func (f *File) extractCondFmtDataBarRule(ID string, format *ConditionalFormatOptions, condFmts []decodeX14ConditionalFormatting) {
3032+
for _, condFmt := range condFmts {
3033+
for _, rule := range condFmt.CfRule {
3034+
if rule.DataBar != nil && rule.ID == ID {
3035+
format.BarDirection = rule.DataBar.Direction
3036+
if rule.DataBar.Gradient != nil && !*rule.DataBar.Gradient {
3037+
format.BarSolid = true
3038+
}
3039+
if rule.DataBar.BorderColor != nil {
3040+
format.BarBorderColor = "#" + f.getThemeColor(rule.DataBar.BorderColor)
3041+
}
3042+
}
3043+
}
3044+
}
3045+
}
3046+
29933047
// extractCondFmtDataBar provides a function to extract conditional format
29943048
// settings for data bar by given conditional formatting rule.
2995-
func extractCondFmtDataBar(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
3049+
func (f *File) extractCondFmtDataBar(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
29963050
format := ConditionalFormatOptions{Type: "data_bar", Criteria: "="}
29973051
if c.DataBar != nil {
29983052
format.StopIfTrue = c.StopIfTrue
29993053
format.MinType = c.DataBar.Cfvo[0].Type
30003054
format.MinValue = c.DataBar.Cfvo[0].Val
30013055
format.MaxType = c.DataBar.Cfvo[1].Type
30023056
format.MaxValue = c.DataBar.Cfvo[1].Val
3003-
format.BarColor = "#" + strings.TrimPrefix(strings.ToUpper(c.DataBar.Color[0].RGB), "FF")
3057+
format.BarColor = "#" + f.getThemeColor(c.DataBar.Color[0])
30043058
if c.DataBar.ShowValue != nil {
30053059
format.BarOnly = !*c.DataBar.ShowValue
30063060
}
30073061
}
3008-
extractDataBarRule := func(condFmts []decodeX14ConditionalFormatting) {
3009-
for _, condFmt := range condFmts {
3010-
for _, rule := range condFmt.CfRule {
3011-
if rule.DataBar != nil {
3012-
format.BarSolid = !rule.DataBar.Gradient
3013-
format.BarDirection = rule.DataBar.Direction
3014-
if rule.DataBar.BorderColor != nil {
3015-
format.BarBorderColor = "#" + strings.TrimPrefix(strings.ToUpper(rule.DataBar.BorderColor.RGB), "FF")
3016-
}
3017-
}
3018-
}
3019-
}
3020-
}
3021-
extractExtLst := func(extLst *decodeExtLst) {
3062+
extractExtLst := func(ID string, extLst *decodeExtLst) {
30223063
for _, ext := range extLst.Ext {
30233064
if ext.URI == ExtURIConditionalFormattings {
3024-
decodeCondFmts := new(decodeX14ConditionalFormattings)
3065+
decodeCondFmts := new(decodeX14ConditionalFormattingRules)
30253066
if err := xml.Unmarshal([]byte(ext.Content), &decodeCondFmts); err == nil {
3026-
var condFmts []decodeX14ConditionalFormatting
3027-
if err = xml.Unmarshal([]byte(decodeCondFmts.Content), &condFmts); err == nil {
3028-
extractDataBarRule(condFmts)
3029-
}
3067+
f.extractCondFmtDataBarRule(ID, &format, decodeCondFmts.CondFmt)
30303068
}
30313069
}
30323070
}
@@ -3036,7 +3074,7 @@ func extractCondFmtDataBar(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatO
30363074
if err := xml.Unmarshal([]byte(c.ExtLst.Ext), &ext); err == nil && extLst != nil {
30373075
decodeExtLst := new(decodeExtLst)
30383076
if err = xml.Unmarshal([]byte("<extLst>"+extLst.Ext+"</extLst>"), decodeExtLst); err == nil {
3039-
extractExtLst(decodeExtLst)
3077+
extractExtLst(ext.ID, decodeExtLst)
30403078
}
30413079
}
30423080
}
@@ -3045,7 +3083,7 @@ func extractCondFmtDataBar(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatO
30453083

30463084
// extractCondFmtExp provides a function to extract conditional format settings
30473085
// for expression by given conditional formatting rule.
3048-
func extractCondFmtExp(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
3086+
func (f *File) extractCondFmtExp(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
30493087
format := ConditionalFormatOptions{StopIfTrue: c.StopIfTrue, Type: "formula"}
30503088
if c.DxfID != nil {
30513089
format.Format = *c.DxfID
@@ -3058,7 +3096,7 @@ func extractCondFmtExp(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptio
30583096

30593097
// extractCondFmtIconSet provides a function to extract conditional format
30603098
// settings for icon sets by given conditional formatting rule.
3061-
func extractCondFmtIconSet(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
3099+
func (f *File) extractCondFmtIconSet(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
30623100
format := ConditionalFormatOptions{Type: "icon_set"}
30633101
if c.IconSet != nil {
30643102
if c.IconSet.ShowValue != nil {
@@ -3082,7 +3120,7 @@ func (f *File) GetConditionalFormats(sheet string) (map[string][]ConditionalForm
30823120
var opts []ConditionalFormatOptions
30833121
for _, cr := range cf.CfRule {
30843122
if extractFunc, ok := extractContFmtFunc[cr.Type]; ok {
3085-
opts = append(opts, extractFunc(cr, ws.ExtLst))
3123+
opts = append(opts, extractFunc(f, cr, ws.ExtLst))
30863124
}
30873125
}
30883126
conditionalFormats[cf.SQRef] = opts

styles_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,21 @@ func TestGetConditionalFormats(t *testing.T) {
236236
assert.NoError(t, err)
237237
assert.Equal(t, format, opts["A1:A2"])
238238
}
239-
// Test get conditional formats on no exists worksheet
239+
// Test get multiple conditional formats
240240
f := NewFile()
241-
_, err := f.GetConditionalFormats("SheetN")
241+
expected := []ConditionalFormatOptions{
242+
{Type: "data_bar", Criteria: "=", MinType: "num", MaxType: "num", MinValue: "-10", MaxValue: "10", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarOnly: true, BarSolid: true, StopIfTrue: true},
243+
{Type: "data_bar", Criteria: "=", MinType: "min", MaxType: "max", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarDirection: "rightToLeft", BarOnly: true, BarSolid: false, StopIfTrue: true},
244+
}
245+
err := f.SetConditionalFormat("Sheet1", "A1:A2", expected)
246+
assert.NoError(t, err)
247+
opts, err := f.GetConditionalFormats("Sheet1")
248+
assert.NoError(t, err)
249+
assert.Equal(t, expected, opts["A1:A2"])
250+
251+
// Test get conditional formats on no exists worksheet
252+
f = NewFile()
253+
_, err = f.GetConditionalFormats("SheetN")
242254
assert.EqualError(t, err, "sheet SheetN does not exist")
243255
// Test get conditional formats with invalid sheet name
244256
_, err = f.GetConditionalFormats("Sheet:1")

xmlWorksheet.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,14 @@ type decodeX14ConditionalFormattings struct {
720720
Content string `xml:",innerxml"`
721721
}
722722

723+
// decodeX14ConditionalFormattingRules directly maps the conditionalFormattings
724+
// element.
725+
type decodeX14ConditionalFormattingRules struct {
726+
XMLName xml.Name `xml:"conditionalFormattings"`
727+
XMLNSXM string `xml:"xmlns:xm,attr"`
728+
CondFmt []decodeX14ConditionalFormatting `xml:"conditionalFormatting"`
729+
}
730+
723731
// decodeX14ConditionalFormatting directly maps the conditionalFormatting
724732
// element.
725733
type decodeX14ConditionalFormatting struct {
@@ -741,7 +749,7 @@ type decodeX14DataBar struct {
741749
MaxLength int `xml:"maxLength,attr"`
742750
MinLength int `xml:"minLength,attr"`
743751
Border bool `xml:"border,attr,omitempty"`
744-
Gradient bool `xml:"gradient,attr"`
752+
Gradient *bool `xml:"gradient,attr"`
745753
ShowValue bool `xml:"showValue,attr,omitempty"`
746754
Direction string `xml:"direction,attr,omitempty"`
747755
Cfvo []*xlsxCfvo `xml:"cfvo"`

0 commit comments

Comments
 (0)