diff --git a/styles.go b/styles.go index 7f763770..b5df352d 100644 --- a/styles.go +++ b/styles.go @@ -2229,12 +2229,12 @@ func (f *File) newFont(style *Style) *xlsxFont { // If given number format code is not exist, will return -1. func getNumFmtID(styleSheet *xlsxStyleSheet, style *Style) (numFmtID int) { numFmtID = -1 - if styleSheet.NumFmts == nil { - return - } if _, ok := builtInNumFmt[style.NumFmt]; ok { return style.NumFmt } + if styleSheet.NumFmts == nil { + return + } if fmtCode, ok := currencyNumFmt[style.NumFmt]; ok { for _, numFmt := range styleSheet.NumFmts.NumFmt { if numFmt.FormatCode == fmtCode { diff --git a/styles_test.go b/styles_test.go index 19092afa..69266eab 100644 --- a/styles_test.go +++ b/styles_test.go @@ -330,3 +330,18 @@ func TestThemeColor(t *testing.T) { assert.Equal(t, clr[0], clr[1]) } } + +func TestGetNumFmtID(t *testing.T) { + f := NewFile() + + fs1, err := parseFormatStyleSet(`{"protection":{"hidden":false,"locked":false},"number_format":10}`) + assert.NoError(t, err) + id1 := getNumFmtID(&xlsxStyleSheet{}, fs1) + + fs2, err := parseFormatStyleSet(`{"protection":{"hidden":false,"locked":false},"number_format":0}`) + assert.NoError(t, err) + id2 := getNumFmtID(&xlsxStyleSheet{}, fs2) + + assert.NotEqual(t, id1, id2) + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestStyleNumFmt.xlsx"))) +} \ No newline at end of file