This closes #1299 skip write nil values in SetRow (#1301)

Co-authored-by: Thomas Charbonnel <github@charbonnel.email>
pull/2/head
Thomas Charbonnel 2 years ago committed by GitHub
parent 504d469d3d
commit 4a029f7e36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -327,6 +327,9 @@ func (sw *StreamWriter) SetRow(axis string, values []interface{}, opts ...RowOpt
} }
fmt.Fprintf(&sw.rawData, `<row r="%d"%s>`, row, attrs) fmt.Fprintf(&sw.rawData, `<row r="%d"%s>`, row, attrs)
for i, val := range values { for i, val := range values {
if val == nil {
continue
}
axis, err := CoordinatesToCellName(col+i, row) axis, err := CoordinatesToCellName(col+i, row)
if err != nil { if err != nil {
return err return err

@ -209,6 +209,17 @@ func TestSetRow(t *testing.T) {
assert.EqualError(t, streamWriter.SetRow("A", []interface{}{}), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error()) assert.EqualError(t, streamWriter.SetRow("A", []interface{}{}), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error())
} }
func TestSetRowNilValues(t *testing.T) {
file := NewFile()
streamWriter, err := file.NewStreamWriter("Sheet1")
assert.NoError(t, err)
streamWriter.SetRow("A1", []interface{}{nil, nil, Cell{Value: "foo"}})
streamWriter.Flush()
ws, err := file.workSheetReader("Sheet1")
assert.NoError(t, err)
assert.NotEqual(t, ws.SheetData.Row[0].C[0].XMLName.Local, "c")
}
func TestSetCellValFunc(t *testing.T) { func TestSetCellValFunc(t *testing.T) {
f := NewFile() f := NewFile()
sw, err := f.NewStreamWriter("Sheet1") sw, err := f.NewStreamWriter("Sheet1")

Loading…
Cancel
Save