Skip to content

Commit 648cf78

Browse files
thomascharbonnelThomas Charbonnel
authored andcommitted
This closes qax-os#1299 skip write nil values in SetRow (qax-os#1301)
Co-authored-by: Thomas Charbonnel <[email protected]>
1 parent 2d25d0d commit 648cf78

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

stream.go

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ func (sw *StreamWriter) SetRow(axis string, values []interface{}, opts ...RowOpt
327327
}
328328
fmt.Fprintf(&sw.rawData, `<row r="%d"%s>`, row, attrs)
329329
for i, val := range values {
330+
if val == nil {
331+
continue
332+
}
330333
axis, err := CoordinatesToCellName(col+i, row)
331334
if err != nil {
332335
return err

stream_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ func TestSetRow(t *testing.T) {
270270
assert.EqualError(t, streamWriter.SetRow("A", []interface{}{}), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error())
271271
}
272272

273+
func TestSetRowNilValues(t *testing.T) {
274+
file := NewFile()
275+
streamWriter, err := file.NewStreamWriter("Sheet1")
276+
assert.NoError(t, err)
277+
streamWriter.SetRow("A1", []interface{}{nil, nil, Cell{Value: "foo"}})
278+
streamWriter.Flush()
279+
ws, err := file.workSheetReader("Sheet1")
280+
assert.NoError(t, err)
281+
assert.NotEqual(t, ws.SheetData.Row[0].C[0].XMLName.Local, "c")
282+
}
283+
273284
func TestSetCellValFunc(t *testing.T) {
274285
f := NewFile()
275286
sw, err := f.NewStreamWriter("Sheet1")

0 commit comments

Comments
 (0)