From 840c6051b7c7ab2ec233251c4c4296a742a51a14 Mon Sep 17 00:00:00 2001 From: XuShuo Date: Mon, 27 May 2024 13:06:54 +0800 Subject: [PATCH] fix: fix nil sheet model append nil pointer reference. --- build.go | 3 +++ build_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) 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") + +}