Skip to content

Commit

Permalink
This closes qax-os#1299 skip write nil values in SetRow (qax-os#1301)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Charbonnel <github@charbonnel.email>
  • Loading branch information
2 people authored and xuri committed Jul 11, 2023
1 parent 4f00c80 commit a1a57a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stream.go
Expand Up @@ -327,6 +327,9 @@ func (sw *StreamWriter) SetRow(axis string, values []interface{}, opts ...RowOpt
}
fmt.Fprintf(&sw.rawData, `<row r="%d"%s>`, row, attrs)
for i, val := range values {
if val == nil {
continue
}
axis, err := CoordinatesToCellName(col+i, row)
if err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions stream_test.go
Expand Up @@ -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")
Expand Down

0 comments on commit a1a57a6

Please sign in to comment.