diff --git a/stream.go b/stream.go index 1a1af24412..52e65a46c8 100644 --- a/stream.go +++ b/stream.go @@ -327,6 +327,9 @@ func (sw *StreamWriter) SetRow(axis string, values []interface{}, opts ...RowOpt } fmt.Fprintf(&sw.rawData, ``, row, attrs) for i, val := range values { + if val == nil { + continue + } axis, err := CoordinatesToCellName(col+i, row) if err != nil { return err diff --git a/stream_test.go b/stream_test.go index 6843e2064f..8f6a5b4cf5 100644 --- a/stream_test.go +++ b/stream_test.go @@ -209,6 +209,17 @@ func TestSetRow(t *testing.T) { 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) { f := NewFile() sw, err := f.NewStreamWriter("Sheet1")