Skip to content

Commit

Permalink
Merge pull request #820 from lpxxn/fix-empty-row-idx-bug
Browse files Browse the repository at this point in the history
fix: new empty row index bug
  • Loading branch information
tealeg authored Sep 22, 2024
2 parents 5f428c2 + e3e5d8c commit e5487eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (s *Sheet) maybeAddRow(rowCount int) {
loopCnt := rowCount - s.MaxRow
for i := 0; i < loopCnt; i++ {
row := s.cellStore.MakeRow(s)
row.num = i
row.num = s.MaxRow + i
s.setCurrentRow(row)
}
s.MaxRow = rowCount
Expand Down
22 changes: 22 additions & 0 deletions sheet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,25 @@ func TestTemp(t *testing.T) {
c.Assert(xSI.T.Text, qt.Equals, "A cell!")
c.Assert(xSI.R, qt.HasLen, 0)
}

func TestAddEmptyRow(t *testing.T) {
c := qt.New(t)
sourceFile, err := OpenFile("./testdocs/original.xlsx")
c.Assert(err, qt.IsNil)
sheet := sourceFile.Sheets[0]
c.Assert(sheet, qt.IsNotNil)
firstRow, err := sheet.Row(0)
c.Assert(err, qt.IsNil)
cellStr := firstRow.GetCell(0).String()
t.Logf("cell: %s", cellStr)

maxRow := sheet.MaxRow
_, err = sheet.Row(maxRow)
c.Assert(err, qt.IsNil)

firstRow, err = sheet.Row(0)
c.Assert(err, qt.IsNil)
cellStr2 := firstRow.GetCell(0).String()
t.Logf("cell: %s", cellStr2)
c.Assert(cellStr, qt.Equals, cellStr2)
}

0 comments on commit e5487eb

Please sign in to comment.