diff options
author | xuri <xuri.me@gmail.com> | 2021-05-16 00:03:09 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-05-16 00:03:09 +0800 |
commit | 5bf3ea61547df2a36757f14bfba47bf22b747079 (patch) | |
tree | 1839cf89fdeca82246c2995a6a64a58302b9f6b3 /rows.go | |
parent | c8c62c2d2a7da3f8e03ad081a9227bcb47f38c45 (diff) |
This closes #842, avoid empty rows in the tail of the worksheet
Diffstat (limited to 'rows.go')
-rw-r--r-- | rows.go | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -43,15 +43,19 @@ func (f *File) GetRows(sheet string) ([][]string, error) { if err != nil { return nil, err } - results := make([][]string, 0, 64) + results, cur, max := make([][]string, 0, 64), 0, 0 for rows.Next() { + cur++ row, err := rows.Columns() if err != nil { break } results = append(results, row) + if len(row) > 0 { + max = cur + } } - return results, nil + return results[:max], nil } // Rows defines an iterator to a sheet. @@ -161,7 +165,9 @@ func rowXMLHandler(rowIterator *rowXMLIterator, xmlElement *xml.StartElement) { } blank := rowIterator.cellCol - len(rowIterator.columns) val, _ := colCell.getValueFrom(rowIterator.rows.f, rowIterator.d) - rowIterator.columns = append(appendSpace(blank, rowIterator.columns), val) + if val != "" { + rowIterator.columns = append(appendSpace(blank, rowIterator.columns), val) + } } } |