From 60b13affbda954261888a7829c88a32993edb5b2 Mon Sep 17 00:00:00 2001 From: li Date: Fri, 5 Nov 2021 00:01:34 +0800 Subject: Support get current row/col and total rows/cols in the stream reader (#1054) --- rows.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'rows.go') diff --git a/rows.go b/rows.go index 3171ab1..1e20f0a 100644 --- a/rows.go +++ b/rows.go @@ -67,19 +67,29 @@ func (f *File) GetRows(sheet string, opts ...Options) ([][]string, error) { // Rows defines an iterator to a sheet. type Rows struct { - err error - curRow, totalRow, stashRow int - rawCellValue bool - sheet string - f *File - tempFile *os.File - decoder *xml.Decoder + err error + curRow, totalRows, stashRow int + rawCellValue bool + sheet string + f *File + tempFile *os.File + decoder *xml.Decoder +} + +// CurrentRow returns the row number that represents the current row. +func (rows *Rows) CurrentRow() int { + return rows.curRow +} + +// TotalRows returns the total rows count in the worksheet. +func (rows *Rows) TotalRows() int { + return rows.totalRows } // Next will return true if find the next row element. func (rows *Rows) Next() bool { rows.curRow++ - return rows.curRow <= rows.totalRow + return rows.curRow <= rows.totalRows } // Error will return the error when the error occurs. @@ -255,7 +265,7 @@ func (f *File) Rows(sheet string) (*Rows, error) { } } } - rows.totalRow = row + rows.totalRows = row } case xml.EndElement: if xmlElement.Name.Local == "sheetData" { -- cgit v1.2.1