Fix loading Excel rows ended with empty cells

This commit is contained in:
nxshock 2024-02-03 14:44:35 +05:00
parent be675c1174
commit 92f089b828
4 changed files with 17 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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()

Binary file not shown.