From 77af25295ece8863326c99652d615f82385286b2 Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Fri, 18 Aug 2017 20:55:27 +0800 Subject: - Conditional format with formula support, relate issue #75; - go test and readme update --- styles.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index a055782..225cfe5 100644 --- a/styles.go +++ b/styles.go @@ -793,7 +793,7 @@ var validType = map[string]string{ "2_color_scale": "2_color_scale", "3_color_scale": "3_color_scale", "data_bar": "dataBar", - "formula": "expression", // Doesn't support currently + "formula": "expression", } // criteriaType defined the list of valid criteria types. @@ -2540,6 +2540,7 @@ func (f *File) SetConditionalFormat(sheet, area, formatSet string) { "2_color_scale": drawCondFmtColorScale, "3_color_scale": drawCondFmtColorScale, "dataBar": drawCondFmtDataBar, + "expression": drawConfFmtExp, } xlsx := f.workSheetReader(sheet) @@ -2554,7 +2555,7 @@ func (f *File) SetConditionalFormat(sheet, area, formatSet string) { } // Check for valid criteria types. ct, ok = criteriaType[v.Criteria] - if !ok { + if !ok && vt != "expression" { continue } @@ -2672,6 +2673,17 @@ func drawCondFmtDataBar(p int, ct string, format *formatConditional) *xlsxCfRule } } +// drawConfFmtExp provides function to create conditional formatting rule for +// expression by given priority, criteria type and format settings. +func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule { + return &xlsxCfRule{ + Priority: p + 1, + Type: validType[format.Type], + Formula: []string{format.Criteria}, + DxfID: &format.Format, + } +} + // getPaletteColor provides function to convert the RBG color by given string. func getPaletteColor(color string) string { return "FF" + strings.Replace(strings.ToUpper(color), "#", "", -1) -- cgit v1.2.1