diff --git a/rows.go b/rows.go index 853c8f7df3..6f05bbb4a5 100644 --- a/rows.go +++ b/rows.go @@ -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. @@ -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: @@ -111,6 +115,14 @@ func (rows *Rows) Next() bool { } } +// GetStyleID provise a function to get the current Rows' style ID. It will +// return 0 when no style has been set. +// +// styleID := rows.GetStyleID() +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 diff --git a/rows_test.go b/rows_test.go index 4fe28517cd..f1963e4d0e 100644 --- a/rows_test.go +++ b/rows_test.go @@ -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) { diff --git a/test/Book1.xlsx b/test/Book1.xlsx index 6a497e33af..72ab005a7f 100644 Binary files a/test/Book1.xlsx and b/test/Book1.xlsx differ