From 9c77e5ce8af7b9d904adae9fc73703f02490955b Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 28 Apr 2022 15:33:25 +0800 Subject: [PATCH] This closes #1211, improve the compatibility with invalid internal styles count --- styles.go | 2 +- styles_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/styles.go b/styles.go index c04ca3b3b39..11f6f750199 100644 --- a/styles.go +++ b/styles.go @@ -2443,7 +2443,7 @@ func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, a if borderID != 0 { xf.ApplyBorder = boolPtr(true) } - style.CellXfs.Count++ + style.CellXfs.Count = len(style.CellXfs.Xf) + 1 xf.Alignment = alignment if alignment != nil { xf.ApplyAlignment = boolPtr(applyAlignment) diff --git a/styles_test.go b/styles_test.go index a71041dd1e5..156b4e33b1a 100644 --- a/styles_test.go +++ b/styles_test.go @@ -271,14 +271,14 @@ func TestNewStyle(t *testing.T) { f.Styles.CellXfs.Xf = nil style4, err := f.NewStyle(&Style{NumFmt: 160, Lang: "unknown"}) assert.NoError(t, err) - assert.Equal(t, 1, style4) + assert.Equal(t, 0, style4) f = NewFile() f.Styles.NumFmts = nil f.Styles.CellXfs.Xf = nil style5, err := f.NewStyle(&Style{NumFmt: 160, Lang: "zh-cn"}) assert.NoError(t, err) - assert.Equal(t, 1, style5) + assert.Equal(t, 0, style5) } func TestGetDefaultFont(t *testing.T) {