Skip to content

Commit

Permalink
fix qax-os#503 rows next issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ducquangkstn authored and xuri committed Oct 18, 2019
1 parent 13f0005 commit 93a9785
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ type Rows struct {

// Next will return true if find the next row element.
func (rows *Rows) Next() bool {
return rows.curRow < len(rows.rows)
rows.curRow++
return rows.curRow <= len(rows.rows)
}

// Error will return the error when the find next row element
Expand All @@ -67,8 +68,7 @@ func (rows *Rows) Error() error {

// Columns return the current row's column values
func (rows *Rows) Columns() ([]string, error) {
curRow := rows.rows[rows.curRow]
rows.curRow++
curRow := rows.rows[rows.curRow-1]

columns := make([]string, len(curRow.C))
d := rows.f.sharedStringsReader()
Expand Down
20 changes: 20 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestRows(t *testing.T) {
Expand Down Expand Up @@ -41,6 +42,25 @@ func TestRows(t *testing.T) {
}
}

// test bug https://github.com/360EntSecGroup-Skylar/excelize/issues/502
func TestRowsIterator(t *testing.T) {
const (
sheet2 = "Sheet2"
expectedNumRow = 11
)
xlsx, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
require.NoError(t, err)

rows, err := xlsx.Rows(sheet2)
require.NoError(t, err)
var rowCount int
for rows.Next() {
rowCount++
require.True(t, rowCount <= expectedNumRow, "rowCount is greater than expected")
}
assert.Equal(t, expectedNumRow, rowCount)
}

func TestRowsError(t *testing.T) {
xlsx, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
if !assert.NoError(t, err) {
Expand Down

0 comments on commit 93a9785

Please sign in to comment.