diff options
author | Thomas Charbonnel <thomascharbonnel@users.noreply.github.com> | 2022-08-11 00:20:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 00:20:48 +0800 |
commit | ed91cddea59ce15da87ab744ac20b465a36ed5ef (patch) | |
tree | 1ab4a75b5a903e20253a93393bc9561bb86ed186 /rows.go | |
parent | b8ceaf7bf61daecad8717abec90a8e0badb64806 (diff) |
This closes #1296, add new function `GetRowOpts` for stream reader (#1297)
- Support get rows properties by `GetRowOpts` function
- New exported constant `MaxCellStyles`
Diffstat (limited to 'rows.go')
-rw-r--r-- | rows.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -80,12 +80,14 @@ type Rows struct { sst *xlsxSST decoder *xml.Decoder token xml.Token + curRowOpts, seekRowOpts RowOpts } // Next will return true if find the next row element. func (rows *Rows) Next() bool { rows.seekRow++ if rows.curRow >= rows.seekRow { + rows.curRowOpts = rows.seekRowOpts return true } for { @@ -101,6 +103,7 @@ func (rows *Rows) Next() bool { rows.curRow = rowNum } rows.token = token + rows.curRowOpts = extractRowOpts(xmlElement.Attr) return true } case xml.EndElement: @@ -111,6 +114,11 @@ func (rows *Rows) Next() bool { } } +// GetRowOpts will return the RowOpts of the current row. +func (rows *Rows) GetRowOpts() RowOpts { + return rows.curRowOpts +} + // Error will return the error when the error occurs. func (rows *Rows) Error() error { return rows.err @@ -151,6 +159,8 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) { } else if rows.token == nil { rows.curRow++ } + rows.token = token + rows.seekRowOpts = extractRowOpts(xmlElement.Attr) if rows.curRow > rows.seekRow { rows.token = nil return rowIterator.columns, rowIterator.err @@ -170,6 +180,20 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) { return rowIterator.columns, rowIterator.err } +func extractRowOpts(attrs []xml.Attr) RowOpts { + rowOpts := RowOpts{Height: defaultRowHeight} + if styleID, err := attrValToInt("s", attrs); err == nil && styleID > 0 && styleID < MaxCellStyles { + rowOpts.StyleID = styleID + } + if hidden, err := attrValToBool("hidden", attrs); err == nil { + rowOpts.Hidden = hidden + } + if height, err := attrValToFloat("ht", attrs); err == nil { + rowOpts.Height = height + } + return rowOpts +} + // appendSpace append blank characters to slice by given length and source slice. func appendSpace(l int, s []string) []string { for i := 1; i < l; i++ { |