Skip to content

Commit 94e86dc

Browse files
committed
This renamed conditional format type iconSet to icon_set
- Remove Minimum, Maximum, MinLength, and MaxLength fields from the type `ConditionalFormatOptions` - Update unit tests and format code
1 parent f143dd5 commit 94e86dc

6 files changed

+31
-35
lines changed

calc.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -13426,7 +13426,8 @@ func (fn *formulaFuncs) LEFTB(argsList *list.List) formulaArg {
1342613426
return fn.leftRight("LEFTB", argsList)
1342713427
}
1342813428

13429-
// leftRight is an implementation of the formula functions LEFT, LEFTB, RIGHT, RIGHTB.
13429+
// leftRight is an implementation of the formula functions LEFT, LEFTB, RIGHT,
13430+
// RIGHTB.
1343013431
func (fn *formulaFuncs) leftRight(name string, argsList *list.List) formulaArg {
1343113432
if argsList.Len() < 1 {
1343213433
return newErrorFormulaArg(formulaErrorVALUE, fmt.Sprintf("%s requires at least 1 argument", name))
@@ -13483,9 +13484,6 @@ func (fn *formulaFuncs) LEN(argsList *list.List) formulaArg {
1348313484
// 1 byte per character. The syntax of the function is:
1348413485
//
1348513486
// LENB(text)
13486-
//
13487-
// TODO: the languages that support DBCS include Japanese, Chinese
13488-
// (Simplified), Chinese (Traditional), and Korean.
1348913487
func (fn *formulaFuncs) LENB(argsList *list.List) formulaArg {
1349013488
if argsList.Len() != 1 {
1349113489
return newErrorFormulaArg(formulaErrorVALUE, "LENB requires 1 string argument")

chart_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ func TestAddChart(t *testing.T) {
153153
{Name: "Sheet1!$A$37", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$37:$D$37"},
154154
}
155155
series2 := []ChartSeries{
156-
{Name: "Sheet1!$A$30", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$30:$D$30",
156+
{
157+
Name: "Sheet1!$A$30", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$30:$D$30",
157158
Fill: Fill{Type: "pattern", Color: []string{"000000"}, Pattern: 1},
158-
Marker: ChartMarker{Symbol: "none", Size: 10}},
159+
Marker: ChartMarker{Symbol: "none", Size: 10},
160+
},
159161
{Name: "Sheet1!$A$31", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$31:$D$31"},
160162
{Name: "Sheet1!$A$32", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$32:$D$32"},
161163
{Name: "Sheet1!$A$33", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$33:$D$33"},

excelize_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,8 @@ func TestConditionalFormat(t *testing.T) {
10521052
Type: "cell",
10531053
Criteria: "between",
10541054
Format: format1,
1055-
Minimum: "6",
1056-
Maximum: "8",
1055+
MinValue: "6",
1056+
MaxValue: "8",
10571057
},
10581058
},
10591059
))

styles.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ var validType = map[string]string{
808808
"3_color_scale": "3_color_scale",
809809
"data_bar": "dataBar",
810810
"formula": "expression",
811-
"iconSet": "iconSet",
811+
"icon_set": "iconSet",
812812
}
813813

814814
// criteriaType defined the list of valid criteria types.
@@ -2843,12 +2843,12 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error {
28432843
// ---------------+------------------------------------
28442844
// cell | Criteria
28452845
// | Value
2846-
// | Minimum
2847-
// | Maximum
2846+
// | MinValue
2847+
// | MaxValue
28482848
// date | Criteria
28492849
// | Value
2850-
// | Minimum
2851-
// | Maximum
2850+
// | MinValue
2851+
// | MaxValue
28522852
// time_period | Criteria
28532853
// text | Criteria
28542854
// | Value
@@ -2887,7 +2887,7 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error {
28872887
// | BarDirection
28882888
// | BarOnly
28892889
// | BarSolid
2890-
// iconSet | IconStyle
2890+
// icon_set | IconStyle
28912891
// | ReverseIcons
28922892
// | IconsOnly
28932893
// formula | Criteria
@@ -2999,7 +2999,7 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error {
29992999
// },
30003000
// )
30013001
//
3002-
// type: Minimum - The 'Minimum' parameter is used to set the lower limiting
3002+
// type: MinValue - The 'MinValue' parameter is used to set the lower limiting
30033003
// value when the criteria is either "between" or "not between".
30043004
//
30053005
// // Highlight cells rules: between...
@@ -3009,13 +3009,13 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error {
30093009
// Type: "cell",
30103010
// Criteria: "between",
30113011
// Format: format,
3012-
// Minimum: "6",
3013-
// Maximum: "8",
3012+
// MinValue: 6",
3013+
// MaxValue: 8",
30143014
// },
30153015
// },
30163016
// )
30173017
//
3018-
// type: Maximum - The 'Maximum' parameter is used to set the upper limiting
3018+
// type: MaxValue - The 'MaxValue' parameter is used to set the upper limiting
30193019
// value when the criteria is either "between" or "not between". See the
30203020
// previous example.
30213021
//
@@ -3361,7 +3361,7 @@ func (f *File) appendCfRule(ws *xlsxWorksheet, rule *xlsxX14CfRule) error {
33613361
func extractCondFmtCellIs(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
33623362
format := ConditionalFormatOptions{StopIfTrue: c.StopIfTrue, Type: "cell", Criteria: operatorType[c.Operator], Format: *c.DxfID}
33633363
if len(c.Formula) == 2 {
3364-
format.Minimum, format.Maximum = c.Formula[0], c.Formula[1]
3364+
format.MinValue, format.MaxValue = c.Formula[0], c.Formula[1]
33653365
return format
33663366
}
33673367
format.Value = c.Formula[0]
@@ -3514,7 +3514,7 @@ func extractCondFmtExp(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptio
35143514
// extractCondFmtIconSet provides a function to extract conditional format
35153515
// settings for icon sets by given conditional formatting rule.
35163516
func extractCondFmtIconSet(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions {
3517-
format := ConditionalFormatOptions{Type: "iconSet"}
3517+
format := ConditionalFormatOptions{Type: "icon_set"}
35183518
if c.IconSet != nil {
35193519
if c.IconSet.ShowValue != nil {
35203520
format.IconsOnly = !*c.IconSet.ShowValue
@@ -3582,11 +3582,11 @@ func drawCondFmtCellIs(p int, ct, GUID string, format *ConditionalFormatOptions)
35823582
StopIfTrue: format.StopIfTrue,
35833583
Type: validType[format.Type],
35843584
Operator: ct,
3585-
DxfID: &format.Format,
3585+
DxfID: intPtr(format.Format),
35863586
}
35873587
// "between" and "not between" criteria require 2 values.
35883588
if ct == "between" || ct == "notBetween" {
3589-
c.Formula = append(c.Formula, []string{format.Minimum, format.Maximum}...)
3589+
c.Formula = append(c.Formula, []string{format.MinValue, format.MaxValue}...)
35903590
}
35913591
if idx := inStrSlice([]string{"equal", "notEqual", "greaterThan", "lessThan", "greaterThanOrEqual", "lessThanOrEqual", "containsText", "notContains", "beginsWith", "endsWith"}, ct, true); idx != -1 {
35923592
c.Formula = append(c.Formula, format.Value)
@@ -3604,7 +3604,7 @@ func drawCondFmtTop10(p int, ct, GUID string, format *ConditionalFormatOptions)
36043604
Bottom: format.Type == "bottom",
36053605
Type: validType[format.Type],
36063606
Rank: 10,
3607-
DxfID: &format.Format,
3607+
DxfID: intPtr(format.Format),
36083608
Percent: format.Percent,
36093609
}
36103610
if rank, err := strconv.Atoi(format.Value); err == nil {
@@ -3621,8 +3621,8 @@ func drawCondFmtAboveAverage(p int, ct, GUID string, format *ConditionalFormatOp
36213621
Priority: p + 1,
36223622
StopIfTrue: format.StopIfTrue,
36233623
Type: validType[format.Type],
3624-
AboveAverage: &format.AboveAverage,
3625-
DxfID: &format.Format,
3624+
AboveAverage: boolPtr(format.AboveAverage),
3625+
DxfID: intPtr(format.Format),
36263626
}, nil
36273627
}
36283628

@@ -3634,7 +3634,7 @@ func drawCondFmtDuplicateUniqueValues(p int, ct, GUID string, format *Conditiona
36343634
Priority: p + 1,
36353635
StopIfTrue: format.StopIfTrue,
36363636
Type: validType[format.Type],
3637-
DxfID: &format.Format,
3637+
DxfID: intPtr(format.Format),
36383638
}, nil
36393639
}
36403640

@@ -3722,7 +3722,7 @@ func drawCondFmtExp(p int, ct, GUID string, format *ConditionalFormatOptions) (*
37223722
StopIfTrue: format.StopIfTrue,
37233723
Type: validType[format.Type],
37243724
Formula: []string{format.Criteria},
3725-
DxfID: &format.Format,
3725+
DxfID: intPtr(format.Format),
37263726
}, nil
37273727
}
37283728

@@ -3774,7 +3774,7 @@ func drawCondFmtIconSet(p int, ct, GUID string, format *ConditionalFormatOptions
37743774
cfRule.IconSet.IconSet = format.IconStyle
37753775
cfRule.IconSet.Reverse = format.ReverseIcons
37763776
cfRule.IconSet.ShowValue = boolPtr(!format.IconsOnly)
3777-
cfRule.Type = format.Type
3777+
cfRule.Type = validType[format.Type]
37783778
return cfRule, nil
37793779
}
37803780

styles_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ func TestSetConditionalFormat(t *testing.T) {
191191
ws.(*xlsxWorksheet).ExtLst = &xlsxExtLst{Ext: "<ext><x14:conditionalFormattings></x14:conditionalFormatting></x14:conditionalFormattings></ext>"}
192192
assert.EqualError(t, f.SetConditionalFormat("Sheet1", "A1:A2", condFmts), "XML syntax error on line 1: element <conditionalFormattings> closed by </conditionalFormatting>")
193193
// Test creating a conditional format with invalid icon set style
194-
assert.EqualError(t, f.SetConditionalFormat("Sheet1", "A1:A2", []ConditionalFormatOptions{{Type: "iconSet", IconStyle: "unknown"}}), ErrParameterInvalid.Error())
194+
assert.EqualError(t, f.SetConditionalFormat("Sheet1", "A1:A2", []ConditionalFormatOptions{{Type: "icon_set", IconStyle: "unknown"}}), ErrParameterInvalid.Error())
195195
}
196196

197197
func TestGetConditionalFormats(t *testing.T) {
198198
for _, format := range [][]ConditionalFormatOptions{
199199
{{Type: "cell", Format: 1, Criteria: "greater than", Value: "6"}},
200-
{{Type: "cell", Format: 1, Criteria: "between", Minimum: "6", Maximum: "8"}},
200+
{{Type: "cell", Format: 1, Criteria: "between", MinValue: "6", MaxValue: "8"}},
201201
{{Type: "top", Format: 1, Criteria: "=", Value: "6"}},
202202
{{Type: "bottom", Format: 1, Criteria: "=", Value: "6"}},
203203
{{Type: "average", AboveAverage: true, Format: 1, Criteria: "="}},
@@ -208,7 +208,7 @@ func TestGetConditionalFormats(t *testing.T) {
208208
{{Type: "data_bar", Criteria: "=", MinType: "min", MaxType: "max", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarOnly: true, BarSolid: true, StopIfTrue: true}},
209209
{{Type: "data_bar", Criteria: "=", MinType: "min", MaxType: "max", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarDirection: "rightToLeft", BarOnly: true, BarSolid: true, StopIfTrue: true}},
210210
{{Type: "formula", Format: 1, Criteria: "="}},
211-
{{Type: "iconSet", IconStyle: "3Arrows", ReverseIcons: true, IconsOnly: true}},
211+
{{Type: "icon_set", IconStyle: "3Arrows", ReverseIcons: true, IconsOnly: true}},
212212
} {
213213
f := NewFile()
214214
err := f.SetConditionalFormat("Sheet1", "A1:A2", format)

xmlWorksheet.go

-4
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,6 @@ type ConditionalFormatOptions struct {
929929
Format int
930930
Criteria string
931931
Value string
932-
Minimum string
933-
Maximum string
934932
MinType string
935933
MidType string
936934
MaxType string
@@ -940,8 +938,6 @@ type ConditionalFormatOptions struct {
940938
MinColor string
941939
MidColor string
942940
MaxColor string
943-
MinLength string
944-
MaxLength string
945941
BarColor string
946942
BarBorderColor string
947943
BarDirection string

0 commit comments

Comments
 (0)