diff options
author | xuri <xuri.me@gmail.com> | 2018-07-26 09:46:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-26 09:46:26 +0800 |
commit | cddcf852c282e4212bc2e90720ed55640fb86847 (patch) | |
tree | d5b0077081fd5c020354dab6f62d93acfb3d042b /styles_test.go | |
parent | a3571ee39bec82d15d9a183aed7f7db39e0a160f (diff) | |
parent | db7a605cf8384f86dd3d3f766050a201b5f10eec (diff) |
Merge pull request #253 from alex-whitney/252-color-scale-cond-formatting
Use min/mid/max value for 2 and 3 color scale conditional formatting
Diffstat (limited to 'styles_test.go')
-rw-r--r-- | styles_test.go | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/styles_test.go b/styles_test.go new file mode 100644 index 0000000..baa66f0 --- /dev/null +++ b/styles_test.go @@ -0,0 +1,134 @@ +package excelize + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSetConditionalFormat(t *testing.T) { + cases := []struct { + label string + format string + rules []*xlsxCfRule + }{{ + label: "3_color_scale", + format: `[{ + "type":"3_color_scale", + "criteria":"=", + "min_type":"num", + "mid_type":"num", + "max_type":"num", + "min_value": "-10", + "mid_value": "0", + "max_value": "10", + "min_color":"ff0000", + "mid_color":"00ff00", + "max_color":"0000ff" + }]`, + rules: []*xlsxCfRule{{ + Priority: 1, + Type: "colorScale", + ColorScale: &xlsxColorScale{ + Cfvo: []*xlsxCfvo{{ + Type: "num", + Val: "-10", + }, { + Type: "num", + Val: "0", + }, { + Type: "num", + Val: "10", + }}, + Color: []*xlsxColor{{ + RGB: "FFFF0000", + }, { + RGB: "FF00FF00", + }, { + RGB: "FF0000FF", + }}, + }, + }}, + }, { + label: "3_color_scale default min/mid/max", + format: `[{ + "type":"3_color_scale", + "criteria":"=", + "min_type":"num", + "mid_type":"num", + "max_type":"num", + "min_color":"ff0000", + "mid_color":"00ff00", + "max_color":"0000ff" + }]`, + rules: []*xlsxCfRule{{ + Priority: 1, + Type: "colorScale", + ColorScale: &xlsxColorScale{ + Cfvo: []*xlsxCfvo{{ + Type: "num", + Val: "0", + }, { + Type: "num", + Val: "50", + }, { + Type: "num", + Val: "0", + }}, + Color: []*xlsxColor{{ + RGB: "FFFF0000", + }, { + RGB: "FF00FF00", + }, { + RGB: "FF0000FF", + }}, + }, + }}, + }, { + label: "2_color_scale default min/max", + format: `[{ + "type":"2_color_scale", + "criteria":"=", + "min_type":"num", + "max_type":"num", + "min_color":"ff0000", + "max_color":"0000ff" + }]`, + rules: []*xlsxCfRule{{ + Priority: 1, + Type: "colorScale", + ColorScale: &xlsxColorScale{ + Cfvo: []*xlsxCfvo{{ + Type: "num", + Val: "0", + }, { + Type: "num", + Val: "0", + }}, + Color: []*xlsxColor{{ + RGB: "FFFF0000", + }, { + RGB: "FF0000FF", + }}, + }, + }}, + }} + + for _, testCase := range cases { + xl := NewFile() + const sheet = "Sheet1" + const cellRange = "A1:A1" + + err := xl.SetConditionalFormat(sheet, cellRange, testCase.format) + if err != nil { + t.Fatalf("%s", err) + } + + xlsx := xl.workSheetReader(sheet) + cf := xlsx.ConditionalFormatting + assert.Len(t, cf, 1, testCase.label) + assert.Len(t, cf[0].CfRule, 1, testCase.label) + assert.Equal(t, cellRange, cf[0].SQRef, testCase.label) + assert.EqualValues(t, testCase.rules, cf[0].CfRule, testCase.label) + } +} |