Skip to content

Commit

Permalink
#1296 add GetStyleID to Rows
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Charbonnel <github@charbonnel.email>
  • Loading branch information
Thomas Charbonnel committed Aug 1, 2022
1 parent fd0eb2b commit b8f0c05
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Rows struct {
sst *xlsxSST
decoder *xml.Decoder
token xml.Token
styleID int
}

// Next will return true if find the next row element.
Expand All @@ -101,6 +102,9 @@ func (rows *Rows) Next() bool {
rows.curRow = rowNum
}
rows.token = token
if styleID, _ := attrValToInt("s", xmlElement.Attr); styleID != 0 {
rows.styleID = styleID
}
return true
}
case xml.EndElement:
Expand All @@ -111,6 +115,10 @@ func (rows *Rows) Next() bool {
}
}

func (rows *Rows) GetStyleID() int {
return rows.styleID
}

// Error will return the error when the error occurs.
func (rows *Rows) Error() error {
return rows.err
Expand Down
13 changes: 13 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ func TestRowsIterator(t *testing.T) {
assert.Equal(t, expectedNumRow, rowCount)
}

func TestRowsGetStyleID(t *testing.T) {
sheetName, expectedRowStyleID := "Sheet2", 1
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
require.NoError(t, err)

rows, err := f.Rows(sheetName)
require.NoError(t, err)
rows.Next()
rowStyleID := rows.GetStyleID()

assert.Equal(t, expectedRowStyleID, rowStyleID)
}

func TestRowsError(t *testing.T) {
f, err := OpenFile(filepath.Join("test", "Book1.xlsx"))
if !assert.NoError(t, err) {
Expand Down
Binary file modified test/Book1.xlsx
Binary file not shown.

0 comments on commit b8f0c05

Please sign in to comment.