diff options
author | xuri <xuri.me@gmail.com> | 2019-12-31 01:01:16 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2019-12-31 01:01:16 +0800 |
commit | 5f5ec76740704a8362e5a120b4a3582b409a5fdd (patch) | |
tree | 91b258747b6126a2bd0226db13aa6c9af5be0d64 /rows.go | |
parent | 09485b3f9f0aefc58d51462aed65c2416205c591 (diff) |
Fix #551, handle empty rows in streaming reading
Diffstat (limited to 'rows.go')
-rw-r--r-- | rows.go | 38 |
1 files changed, 26 insertions, 12 deletions
@@ -23,12 +23,20 @@ import ( // GetRows return all the rows in a sheet by given worksheet name (case // sensitive). For example: // -// rows, err := f.GetRows("Sheet1") -// for _, row := range rows { +// rows, err := f.Rows("Sheet1") +// if err != nil { +// println(err.Error()) +// return +// } +// for rows.Next() { +// row, err := rows.Columns() +// if err != nil { +// println(err.Error()) +// } // for _, colCell := range row { -// fmt.Print(colCell, "\t") +// print(colCell, "\t") // } -// fmt.Println() +// println() // } // func (f *File) GetRows(sheet string) ([][]string, error) { @@ -52,13 +60,13 @@ func (f *File) GetRows(sheet string) ([][]string, error) { // Rows defines an iterator to a sheet type Rows struct { - err error - f *File - rows []xlsxRow - sheet string - curRow int - totalRow int - decoder *xml.Decoder + err error + curRow, totalRow, stashRow int + sheet string + stashColumn []string + rows []xlsxRow + f *File + decoder *xml.Decoder } // Next will return true if find the next row element. @@ -80,6 +88,11 @@ func (rows *Rows) Columns() ([]string, error) { row, cellCol int columns []string ) + + if rows.stashRow >= rows.curRow { + return columns, err + } + d := rows.f.sharedStringsReader() for { token, _ := rows.decoder.Token() @@ -97,6 +110,8 @@ func (rows *Rows) Columns() ([]string, error) { return columns, err } if row > rows.curRow { + rows.stashRow = row - 1 + rows.stashColumn = columns return columns, err } } @@ -121,7 +136,6 @@ func (rows *Rows) Columns() ([]string, error) { if inElement == "row" { return columns, err } - default: } } return columns, err |