From 94e86dca31476ec79f0643ae9645893507ec56f3 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 22 Feb 2023 22:46:36 +0800 Subject: [PATCH] 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 --- calc.go | 6 ++---- chart_test.go | 6 ++++-- excelize_test.go | 4 ++-- styles.go | 40 ++++++++++++++++++++-------------------- styles_test.go | 6 +++--- xmlWorksheet.go | 4 ---- 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/calc.go b/calc.go index f8d4616..70b5409 100644 --- a/calc.go +++ b/calc.go @@ -13426,7 +13426,8 @@ func (fn *formulaFuncs) LEFTB(argsList *list.List) formulaArg { return fn.leftRight("LEFTB", argsList) } -// leftRight is an implementation of the formula functions LEFT, LEFTB, RIGHT, RIGHTB. +// leftRight is an implementation of the formula functions LEFT, LEFTB, RIGHT, +// RIGHTB. func (fn *formulaFuncs) leftRight(name string, argsList *list.List) formulaArg { if argsList.Len() < 1 { return newErrorFormulaArg(formulaErrorVALUE, fmt.Sprintf("%s requires at least 1 argument", name)) @@ -13483,9 +13484,6 @@ func (fn *formulaFuncs) LEN(argsList *list.List) formulaArg { // 1 byte per character. The syntax of the function is: // // LENB(text) -// -// TODO: the languages that support DBCS include Japanese, Chinese -// (Simplified), Chinese (Traditional), and Korean. func (fn *formulaFuncs) LENB(argsList *list.List) formulaArg { if argsList.Len() != 1 { return newErrorFormulaArg(formulaErrorVALUE, "LENB requires 1 string argument") diff --git a/chart_test.go b/chart_test.go index 9a8660c..14adb06 100644 --- a/chart_test.go +++ b/chart_test.go @@ -153,9 +153,11 @@ func TestAddChart(t *testing.T) { {Name: "Sheet1!$A$37", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$37:$D$37"}, } series2 := []ChartSeries{ - {Name: "Sheet1!$A$30", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$30:$D$30", + { + Name: "Sheet1!$A$30", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$30:$D$30", Fill: Fill{Type: "pattern", Color: []string{"000000"}, Pattern: 1}, - Marker: ChartMarker{Symbol: "none", Size: 10}}, + Marker: ChartMarker{Symbol: "none", Size: 10}, + }, {Name: "Sheet1!$A$31", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$31:$D$31"}, {Name: "Sheet1!$A$32", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$32:$D$32"}, {Name: "Sheet1!$A$33", Categories: "Sheet1!$B$29:$D$29", Values: "Sheet1!$B$33:$D$33"}, diff --git a/excelize_test.go b/excelize_test.go index 7e19c5b..ea3a41b 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -1052,8 +1052,8 @@ func TestConditionalFormat(t *testing.T) { Type: "cell", Criteria: "between", Format: format1, - Minimum: "6", - Maximum: "8", + MinValue: "6", + MaxValue: "8", }, }, )) diff --git a/styles.go b/styles.go index 78083f2..7483d30 100644 --- a/styles.go +++ b/styles.go @@ -808,7 +808,7 @@ var validType = map[string]string{ "3_color_scale": "3_color_scale", "data_bar": "dataBar", "formula": "expression", - "iconSet": "iconSet", + "icon_set": "iconSet", } // criteriaType defined the list of valid criteria types. @@ -2843,12 +2843,12 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error { // ---------------+------------------------------------ // cell | Criteria // | Value -// | Minimum -// | Maximum +// | MinValue +// | MaxValue // date | Criteria // | Value -// | Minimum -// | Maximum +// | MinValue +// | MaxValue // time_period | Criteria // text | Criteria // | Value @@ -2887,7 +2887,7 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error { // | BarDirection // | BarOnly // | BarSolid -// iconSet | IconStyle +// icon_set | IconStyle // | ReverseIcons // | IconsOnly // formula | Criteria @@ -2999,7 +2999,7 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error { // }, // ) // -// type: Minimum - The 'Minimum' parameter is used to set the lower limiting +// type: MinValue - The 'MinValue' parameter is used to set the lower limiting // value when the criteria is either "between" or "not between". // // // Highlight cells rules: between... @@ -3009,13 +3009,13 @@ func (f *File) SetCellStyle(sheet, hCell, vCell string, styleID int) error { // Type: "cell", // Criteria: "between", // Format: format, -// Minimum: "6", -// Maximum: "8", +// MinValue: 6", +// MaxValue: 8", // }, // }, // ) // -// type: Maximum - The 'Maximum' parameter is used to set the upper limiting +// type: MaxValue - The 'MaxValue' parameter is used to set the upper limiting // value when the criteria is either "between" or "not between". See the // previous example. // @@ -3361,7 +3361,7 @@ func (f *File) appendCfRule(ws *xlsxWorksheet, rule *xlsxX14CfRule) error { func extractCondFmtCellIs(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions { format := ConditionalFormatOptions{StopIfTrue: c.StopIfTrue, Type: "cell", Criteria: operatorType[c.Operator], Format: *c.DxfID} if len(c.Formula) == 2 { - format.Minimum, format.Maximum = c.Formula[0], c.Formula[1] + format.MinValue, format.MaxValue = c.Formula[0], c.Formula[1] return format } format.Value = c.Formula[0] @@ -3514,7 +3514,7 @@ func extractCondFmtExp(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptio // extractCondFmtIconSet provides a function to extract conditional format // settings for icon sets by given conditional formatting rule. func extractCondFmtIconSet(c *xlsxCfRule, extLst *xlsxExtLst) ConditionalFormatOptions { - format := ConditionalFormatOptions{Type: "iconSet"} + format := ConditionalFormatOptions{Type: "icon_set"} if c.IconSet != nil { if c.IconSet.ShowValue != nil { format.IconsOnly = !*c.IconSet.ShowValue @@ -3582,11 +3582,11 @@ func drawCondFmtCellIs(p int, ct, GUID string, format *ConditionalFormatOptions) StopIfTrue: format.StopIfTrue, Type: validType[format.Type], Operator: ct, - DxfID: &format.Format, + DxfID: intPtr(format.Format), } // "between" and "not between" criteria require 2 values. if ct == "between" || ct == "notBetween" { - c.Formula = append(c.Formula, []string{format.Minimum, format.Maximum}...) + c.Formula = append(c.Formula, []string{format.MinValue, format.MaxValue}...) } if idx := inStrSlice([]string{"equal", "notEqual", "greaterThan", "lessThan", "greaterThanOrEqual", "lessThanOrEqual", "containsText", "notContains", "beginsWith", "endsWith"}, ct, true); idx != -1 { c.Formula = append(c.Formula, format.Value) @@ -3604,7 +3604,7 @@ func drawCondFmtTop10(p int, ct, GUID string, format *ConditionalFormatOptions) Bottom: format.Type == "bottom", Type: validType[format.Type], Rank: 10, - DxfID: &format.Format, + DxfID: intPtr(format.Format), Percent: format.Percent, } if rank, err := strconv.Atoi(format.Value); err == nil { @@ -3621,8 +3621,8 @@ func drawCondFmtAboveAverage(p int, ct, GUID string, format *ConditionalFormatOp Priority: p + 1, StopIfTrue: format.StopIfTrue, Type: validType[format.Type], - AboveAverage: &format.AboveAverage, - DxfID: &format.Format, + AboveAverage: boolPtr(format.AboveAverage), + DxfID: intPtr(format.Format), }, nil } @@ -3634,7 +3634,7 @@ func drawCondFmtDuplicateUniqueValues(p int, ct, GUID string, format *Conditiona Priority: p + 1, StopIfTrue: format.StopIfTrue, Type: validType[format.Type], - DxfID: &format.Format, + DxfID: intPtr(format.Format), }, nil } @@ -3722,7 +3722,7 @@ func drawCondFmtExp(p int, ct, GUID string, format *ConditionalFormatOptions) (* StopIfTrue: format.StopIfTrue, Type: validType[format.Type], Formula: []string{format.Criteria}, - DxfID: &format.Format, + DxfID: intPtr(format.Format), }, nil } @@ -3774,7 +3774,7 @@ func drawCondFmtIconSet(p int, ct, GUID string, format *ConditionalFormatOptions cfRule.IconSet.IconSet = format.IconStyle cfRule.IconSet.Reverse = format.ReverseIcons cfRule.IconSet.ShowValue = boolPtr(!format.IconsOnly) - cfRule.Type = format.Type + cfRule.Type = validType[format.Type] return cfRule, nil } diff --git a/styles_test.go b/styles_test.go index 864f14f..ae7267a 100644 --- a/styles_test.go +++ b/styles_test.go @@ -191,13 +191,13 @@ func TestSetConditionalFormat(t *testing.T) { ws.(*xlsxWorksheet).ExtLst = &xlsxExtLst{Ext: ""} assert.EqualError(t, f.SetConditionalFormat("Sheet1", "A1:A2", condFmts), "XML syntax error on line 1: element closed by ") // Test creating a conditional format with invalid icon set style - assert.EqualError(t, f.SetConditionalFormat("Sheet1", "A1:A2", []ConditionalFormatOptions{{Type: "iconSet", IconStyle: "unknown"}}), ErrParameterInvalid.Error()) + assert.EqualError(t, f.SetConditionalFormat("Sheet1", "A1:A2", []ConditionalFormatOptions{{Type: "icon_set", IconStyle: "unknown"}}), ErrParameterInvalid.Error()) } func TestGetConditionalFormats(t *testing.T) { for _, format := range [][]ConditionalFormatOptions{ {{Type: "cell", Format: 1, Criteria: "greater than", Value: "6"}}, - {{Type: "cell", Format: 1, Criteria: "between", Minimum: "6", Maximum: "8"}}, + {{Type: "cell", Format: 1, Criteria: "between", MinValue: "6", MaxValue: "8"}}, {{Type: "top", Format: 1, Criteria: "=", Value: "6"}}, {{Type: "bottom", Format: 1, Criteria: "=", Value: "6"}}, {{Type: "average", AboveAverage: true, Format: 1, Criteria: "="}}, @@ -208,7 +208,7 @@ func TestGetConditionalFormats(t *testing.T) { {{Type: "data_bar", Criteria: "=", MinType: "min", MaxType: "max", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarOnly: true, BarSolid: true, StopIfTrue: true}}, {{Type: "data_bar", Criteria: "=", MinType: "min", MaxType: "max", BarBorderColor: "#0000FF", BarColor: "#638EC6", BarDirection: "rightToLeft", BarOnly: true, BarSolid: true, StopIfTrue: true}}, {{Type: "formula", Format: 1, Criteria: "="}}, - {{Type: "iconSet", IconStyle: "3Arrows", ReverseIcons: true, IconsOnly: true}}, + {{Type: "icon_set", IconStyle: "3Arrows", ReverseIcons: true, IconsOnly: true}}, } { f := NewFile() err := f.SetConditionalFormat("Sheet1", "A1:A2", format) diff --git a/xmlWorksheet.go b/xmlWorksheet.go index 98727de..97bbfdd 100644 --- a/xmlWorksheet.go +++ b/xmlWorksheet.go @@ -929,8 +929,6 @@ type ConditionalFormatOptions struct { Format int Criteria string Value string - Minimum string - Maximum string MinType string MidType string MaxType string @@ -940,8 +938,6 @@ type ConditionalFormatOptions struct { MinColor string MidColor string MaxColor string - MinLength string - MaxLength string BarColor string BarBorderColor string BarDirection string