Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamWriter.SetRow should not insert a cell when value is nil #1299

Closed
thomascharbonnel opened this issue Aug 3, 2022 · 1 comment
Closed

Comments

@thomascharbonnel
Copy link
Contributor

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:

  1. Create a new document using StreamWriter
  2. Set a row-level style using RowOpts (this style should apply to all the cells in that row unless overwritten by a specific cell
  3. Insert a Cell{} preceded by nil cells using SetRow. (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.

@thomascharbonnel
Copy link
Contributor Author

It's worth discussing whether an empty Cell{} should also be written or not, on top of nil

thomascharbonnel pushed a commit to thomascharbonnel/excelize that referenced this issue Aug 3, 2022
@xuri xuri closed this as completed in 4a029f7 Aug 4, 2022
xuri pushed a commit to carbin-gun/excelize that referenced this issue Oct 9, 2022
xuri pushed a commit to JDavidVR/excelize that referenced this issue Jul 11, 2023
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant