diff --git a/build.go b/build.go index c90232a..bc09149 100644 --- a/build.go +++ b/build.go @@ -84,6 +84,9 @@ func write(sheetModels []SheetModel, opts ...Option) (*excelize.File, error) { f := excelize.NewFile() sheetLinesCount := make(map[string]int) for _, sheetModel := range sheetModels { + if sheetModel == nil { + return nil, errors.New("nil reference row append is not allowed") + } sheetName := sheetModel.SheetName() if sheetName == "" { return nil, errors.New("sheetModel must have a sheet name") diff --git a/build_test.go b/build_test.go index a422009..f449e34 100644 --- a/build_test.go +++ b/build_test.go @@ -379,3 +379,11 @@ func TestWithHeadless(t *testing.T) { t.Error(err) } } + +func TestAppendNilRow(t *testing.T) { + var models []SheetModel + models = append(models, nil) + err := WriteExcelSaveAs("test16.xlsx", models) + assert.EqualError(t, err, "nil reference row append is not allowed") + +}