From 92f089b828d89c73453e5e3326de631c816a154e Mon Sep 17 00:00:00 2001 From: nxshock Date: Sat, 3 Feb 2024 14:44:35 +0500 Subject: [PATCH] Fix loading Excel rows ended with empty cells --- options.go | 11 +++++++++++ readerxlsx.go | 2 ++ readerxlsx_test.go | 4 ++++ testdata/xlsx/38_049RMZ_all.xlsx | Bin 9124 -> 7133 bytes 4 files changed, 17 insertions(+) diff --git a/options.go b/options.go index 27dd2e9..6496642 100644 --- a/options.go +++ b/options.go @@ -60,3 +60,14 @@ type Options struct { // Column names list columnNames []string } + +func (o *Options) fieldCount() int { + fCount := 0 + for i := range o.fieldsTypes { + if o.fieldsTypes[i] != ' ' { + fCount++ + } + } + + return fCount +} diff --git a/readerxlsx.go b/readerxlsx.go index 4b094ba..9d42097 100644 --- a/readerxlsx.go +++ b/readerxlsx.go @@ -109,6 +109,8 @@ func (r *XlsxReader) GetRow(asStrings bool) ([]any, error) { args = append(args, parsedValue) } + args = append(args, make([]any, r.options.fieldCount()-len(args))...) + return args, nil } diff --git a/readerxlsx_test.go b/readerxlsx_test.go index 3bb56c6..ca3249e 100644 --- a/readerxlsx_test.go +++ b/readerxlsx_test.go @@ -29,6 +29,10 @@ func TestXlsxReaderBasic(t *testing.T) { assert.Equal(t, []any{"7710146208", nil, nil, "99386901", "99386901", "304722813269", "TSENTRALNYY TELEGRAF", "780000334079", "780000334079", "10432641", t1, t2, 50.00, 0.80, 49.20, "553691******1214", "026094", "D", "MC OTHER"}, row) row, err = xlsxReader.GetRow(false) + assert.NoError(t, err) + assert.Len(t, row, 19) + + _, err = xlsxReader.GetRow(false) assert.Equal(t, io.EOF, err) err = xlsxReader.Close() diff --git a/testdata/xlsx/38_049RMZ_all.xlsx b/testdata/xlsx/38_049RMZ_all.xlsx index bae2e0f3567080ce06afdc37d486bfd3490667c8..96d91bdf6fbfe172d1d7f708318d59064cd6d3c3 100644 GIT binary patch literal 7133 zcmaKR1z1#D_dd;HehHP4wdbLLrl&VJWg?_THK8p?=BKs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