-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Description
When using StreamWriter's SetRow, one has to pass a []interface{} of values. However, when a value given is nil (eg. values := []any{nil, nil, excelize.Cell{}}, Excelize still creates an XML c cell. This creates problems when a row-level style has been set.
Steps to reproduce the issue:
- Create a new document using StreamWriter
- Set a row-level style using
RowOpts(this style should apply to all the cells in that row unless overwritten by a specific cell - Insert a
Cell{}preceded bynilcells usingSetRow. (eg. A1 and B1 are nil but C1 contains "My string")
Describe the results you received:
If N nil cells are inserted before a Cell{}, Excel will show those cells using the default style (white background) rather than the row-level style.
Ie. the XML worksheet will contain <c t="str" r="A1"></c><c t="str" r="B1"></c><c t="str" r="C1">My string</c>.
Describe the results you expected:
Empty cells should not be written to the XML worksheet, so A1 and B1 should be empty cells using the row-level style.
XML should be <c t="str" r="C1">My string</c>.
This is Excel's behavior
Output of go version:
go version 1.18.3 linux/amd64
Excelize version or commit ID:
master
Environment details (OS, Microsoft Excel™ version, physical, etc.):
Running on Red Hat Linux.
Library code to change
https://github.com/qax-os/excelize/blob/master/stream.go#L329 This is the issue, the loop should test if val == nil and if yes it should continue.