summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-04-28 15:33:25 +0800
committerGitHub <noreply@github.com>2022-04-28 15:33:25 +0800
commitdf91b34a3f816a865ba6f9ea7707c668552df9d6 (patch)
tree95d2dad45d9f94d86de7e414741335b699ea9f11
parent0f7a0c8f3b5c9abd5858cab80902296d1639625f (diff)
This closes #1211, improve the compatibility with invalid internal styles count
-rw-r--r--styles.go2
-rw-r--r--styles_test.go4
2 files changed, 3 insertions, 3 deletions
diff --git a/styles.go b/styles.go
index c04ca3b..11f6f75 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 a71041d..156b4e3 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) {