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) --- col.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'col.go') diff --git a/col.go b/col.go index ffd49dd..c688201 100644 --- a/col.go +++ b/col.go @@ -32,12 +32,22 @@ const ( // Cols defines an iterator to a sheet type Cols struct { - err error - curCol, totalCol, stashCol, totalRow int - rawCellValue bool - sheet string - f *File - sheetXML []byte + err error + curCol, totalCols, totalRows, stashCol int + rawCellValue bool + sheet string + f *File + sheetXML []byte +} + +// CurrentCol returns the column number that represents the current column. +func (cols *Cols) CurrentCol() int { + return cols.curCol +} + +// TotalCols returns the total columns count in the worksheet. +func (cols *Cols) TotalCols() int { + return cols.totalCols } // GetCols return all the columns in a sheet by given worksheet name (case @@ -71,7 +81,7 @@ func (f *File) GetCols(sheet string, opts ...Options) ([][]string, error) { // Next will return true if the next column is found. func (cols *Cols) Next() bool { cols.curCol++ - return cols.curCol <= cols.totalCol + return cols.curCol <= cols.totalCols } // Error will return an error when the error occurs. @@ -159,7 +169,7 @@ func columnXMLHandler(colIterator *columnXMLIterator, xmlElement *xml.StartEleme colIterator.row = colIterator.curRow } } - colIterator.cols.totalRow = colIterator.row + colIterator.cols.totalRows = colIterator.row colIterator.cellCol = 0 } if inElement == "c" { @@ -171,8 +181,8 @@ func columnXMLHandler(colIterator *columnXMLIterator, xmlElement *xml.StartEleme } } } - if colIterator.cellCol > colIterator.cols.totalCol { - colIterator.cols.totalCol = colIterator.cellCol + if colIterator.cellCol > colIterator.cols.totalCols { + colIterator.cols.totalCols = colIterator.cellCol } } } -- cgit v1.2.1