Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit e5487eb

Browse files
authored
Merge pull request #820 from lpxxn/fix-empty-row-idx-bug
fix: new empty row index bug
2 parents 5f428c2 + e3e5d8c commit e5487eb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

sheet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (s *Sheet) maybeAddRow(rowCount int) {
288288
loopCnt := rowCount - s.MaxRow
289289
for i := 0; i < loopCnt; i++ {
290290
row := s.cellStore.MakeRow(s)
291-
row.num = i
291+
row.num = s.MaxRow + i
292292
s.setCurrentRow(row)
293293
}
294294
s.MaxRow = rowCount

sheet_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,25 @@ func TestTemp(t *testing.T) {
823823
c.Assert(xSI.T.Text, qt.Equals, "A cell!")
824824
c.Assert(xSI.R, qt.HasLen, 0)
825825
}
826+
827+
func TestAddEmptyRow(t *testing.T) {
828+
c := qt.New(t)
829+
sourceFile, err := OpenFile("./testdocs/original.xlsx")
830+
c.Assert(err, qt.IsNil)
831+
sheet := sourceFile.Sheets[0]
832+
c.Assert(sheet, qt.IsNotNil)
833+
firstRow, err := sheet.Row(0)
834+
c.Assert(err, qt.IsNil)
835+
cellStr := firstRow.GetCell(0).String()
836+
t.Logf("cell: %s", cellStr)
837+
838+
maxRow := sheet.MaxRow
839+
_, err = sheet.Row(maxRow)
840+
c.Assert(err, qt.IsNil)
841+
842+
firstRow, err = sheet.Row(0)
843+
c.Assert(err, qt.IsNil)
844+
cellStr2 := firstRow.GetCell(0).String()
845+
t.Logf("cell: %s", cellStr2)
846+
c.Assert(cellStr, qt.Equals, cellStr2)
847+
}

0 commit comments

Comments
 (0)