From 3d02726ad4dc3bc6a92d5b68ef8421ac4db44076 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Oct 2022 00:48:16 +0800 Subject: This closes #320, support custom chart axis font style --- styles.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 5299fbd..dc34427 100644 --- a/styles.go +++ b/styles.go @@ -2087,7 +2087,6 @@ func (f *File) getFontID(styleSheet *xlsxStyleSheet, style *Style) (fontID int) // newFont provides a function to add font style by given cell format // settings. func (f *File) newFont(style *Style) *xlsxFont { - fontUnderlineType := map[string]string{"single": "single", "double": "double"} if style.Font.Size < MinFontSize { style.Font.Size = 11 } @@ -2112,9 +2111,8 @@ func (f *File) newFont(style *Style) *xlsxFont { if style.Font.Strike { fnt.Strike = &attrValBool{Val: &style.Font.Strike} } - val, ok := fontUnderlineType[style.Font.Underline] - if ok { - fnt.U = &attrValString{Val: stringPtr(val)} + if idx := inStrSlice(supportedUnderlineTypes, style.Font.Underline, true); idx != -1 { + fnt.U = &attrValString{Val: stringPtr(supportedUnderlineTypes[idx])} } return &fnt } @@ -3100,13 +3098,10 @@ func drawCondFmtCellIs(p int, ct string, format *conditionalOptions) *xlsxCfRule DxfID: &format.Format, } // "between" and "not between" criteria require 2 values. - _, ok := map[string]bool{"between": true, "notBetween": true}[ct] - if ok { - c.Formula = append(c.Formula, format.Minimum) - c.Formula = append(c.Formula, format.Maximum) + if ct == "between" || ct == "notBetween" { + c.Formula = append(c.Formula, []string{format.Minimum, format.Maximum}...) } - _, ok = map[string]bool{"equal": true, "notEqual": true, "greaterThan": true, "lessThan": true, "greaterThanOrEqual": true, "lessThanOrEqual": true, "containsText": true, "notContains": true, "beginsWith": true, "endsWith": true}[ct] - if ok { + 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) } return c @@ -3124,8 +3119,7 @@ func drawCondFmtTop10(p int, ct string, format *conditionalOptions) *xlsxCfRule DxfID: &format.Format, Percent: format.Percent, } - rank, err := strconv.Atoi(format.Value) - if err == nil { + if rank, err := strconv.Atoi(format.Value); err == nil { c.Rank = rank } return c -- cgit v1.2.1