summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDokiy <zhangzongqi@fancydigital.com.cn>2021-12-01 19:11:51 +0800
committerDokiy <zhangzongqi@fancydigital.com.cn>2021-12-01 19:11:51 +0800
commit45a1f08a2ad12ec613fd435ba5efcb830e617a71 (patch)
tree3c0ab5b0483ae53b26e837e9984c4b0fad72b5dd
parentbb0eb4a42be2c004a3c2ce59a8c748a9822b5f99 (diff)
Fix call getNumFmtID with builtInNumFmt return -1
-rw-r--r--styles.go6
-rw-r--r--styles_test.go15
2 files changed, 18 insertions, 3 deletions
diff --git a/styles.go b/styles.go
index 7f76377..b5df352 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 19092af..69266ea 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