未验证 提交 4ca1b305 编写于 作者: xurime's avatar xurime 提交者: GitHub

Merge pull request #1077 from Dokiys/hotfix/get_num_fmt_id

Fix call getNumFmtID with builtInNumFmt return -1
......@@ -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 {
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册