From 5bf3ea61547df2a36757f14bfba47bf22b747079 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 16 May 2021 00:03:09 +0800 Subject: This closes #842, avoid empty rows in the tail of the worksheet --- rows.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'rows.go') diff --git a/rows.go b/rows.go index 451dbe9..4147662 100644 --- a/rows.go +++ b/rows.go @@ -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) + } } } -- cgit v1.2.1