summaryrefslogtreecommitdiff
path: root/rows.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-11-18 22:08:40 +0800
committerxuri <xuri.me@gmail.com>2020-11-18 22:08:40 +0800
commit92c8626f814c3bcb91e30f83de8e68c9b8bb9a5f (patch)
tree86fec139f87ffbbad0ea3f136a622beb1c189ac2 /rows.go
parent2be4bfd410744201f96e79804ef644d26c47f49f (diff)
Fixed #732, support single line with repeated row element in the sheet data
Diffstat (limited to 'rows.go')
-rw-r--r--rows.go34
1 files changed, 16 insertions, 18 deletions
diff --git a/rows.go b/rows.go
index 04a06b9..4f93ed1 100644
--- a/rows.go
+++ b/rows.go
@@ -79,10 +79,10 @@ func (rows *Rows) Error() error {
// Columns return the current row's column values.
func (rows *Rows) Columns() ([]string, error) {
var (
- err error
- inElement string
- row, cellCol int
- columns []string
+ err error
+ inElement string
+ attrR, cellCol, row int
+ columns []string
)
if rows.stashRow >= rows.curRow {
@@ -99,17 +99,13 @@ func (rows *Rows) Columns() ([]string, error) {
case xml.StartElement:
inElement = startElement.Name.Local
if inElement == "row" {
- for _, attr := range startElement.Attr {
- if attr.Name.Local == "r" {
- row, err = strconv.Atoi(attr.Value)
- if err != nil {
- return columns, err
- }
- if row > rows.curRow {
- rows.stashRow = row - 1
- return columns, err
- }
- }
+ row++
+ if attrR, err = attrValToInt("r", startElement.Attr); attrR != 0 {
+ row = attrR
+ }
+ if row > rows.curRow {
+ rows.stashRow = row - 1
+ return columns, err
}
}
if inElement == "c" {
@@ -117,8 +113,7 @@ func (rows *Rows) Columns() ([]string, error) {
colCell := xlsxC{}
_ = rows.decoder.DecodeElement(&colCell, &startElement)
if colCell.R != "" {
- cellCol, _, err = CellNameToCoordinates(colCell.R)
- if err != nil {
+ if cellCol, _, err = CellNameToCoordinates(colCell.R); err != nil {
return columns, err
}
}
@@ -128,7 +123,10 @@ func (rows *Rows) Columns() ([]string, error) {
}
case xml.EndElement:
inElement = startElement.Name.Local
- if inElement == "row" {
+ if row == 0 {
+ row = rows.curRow
+ }
+ if inElement == "row" && row+1 < rows.curRow {
return columns, err
}
}