diff options
author | xuri <xuri.me@gmail.com> | 2021-12-03 00:19:11 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-12-03 00:19:11 +0800 |
commit | 577a07f08c6121d627323db00fdf9e74989a5515 (patch) | |
tree | e8252f418b2ac632d148d272aaeac2a81000d08c /styles.go | |
parent | aa359f1c748b5cbdc57ae032255e8b8940001e0b (diff) |
Simplify code and update unit test
Improve unit test coverage for the functions: `NewStyle`, `SetActiveSheet`, `SearchSheet` and `deleteAndAdjustDefinedNames`
Simplify code and add comments for the function: `deleteAndAdjustDefinedNames`
Diffstat (limited to 'styles.go')
-rw-r--r-- | styles.go | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -2053,8 +2053,8 @@ func (f *File) NewStyle(style interface{}) (int, error) { var getXfIDFuncs = map[string]func(int, xlsxXf, *Style) bool{ "numFmt": func(numFmtID int, xf xlsxXf, style *Style) bool { - if style.NumFmt == 0 && style.CustomNumFmt == nil && numFmtID == -1 { - return xf.NumFmtID != nil || *xf.NumFmtID == 0 + if style.CustomNumFmt == nil && numFmtID == -1 { + return xf.NumFmtID != nil && *xf.NumFmtID == 0 } if style.NegRed || style.Lang != "" || style.DecimalPlaces != 2 { return false @@ -2232,14 +2232,20 @@ func getNumFmtID(styleSheet *xlsxStyleSheet, style *Style) (numFmtID int) { if _, ok := builtInNumFmt[style.NumFmt]; ok { return style.NumFmt } - if styleSheet.NumFmts == nil { - return + for lang, numFmt := range langNumFmt { + if _, ok := numFmt[style.NumFmt]; ok && lang == style.Lang { + numFmtID = style.NumFmt + return + } } if fmtCode, ok := currencyNumFmt[style.NumFmt]; ok { - for _, numFmt := range styleSheet.NumFmts.NumFmt { - if numFmt.FormatCode == fmtCode { - numFmtID = numFmt.NumFmtID - return + numFmtID = style.NumFmt + if styleSheet.NumFmts != nil { + for _, numFmt := range styleSheet.NumFmts.NumFmt { + if numFmt.FormatCode == fmtCode { + numFmtID = numFmt.NumFmtID + return + } } } } |