Skip to content

Commit

Permalink
This closes qax-os#1749, fix incorrect adjust merged cells on remove …
Browse files Browse the repository at this point in the history
…rows (qax-os#1753)
  • Loading branch information
CooolNv authored Dec 13, 2023
1 parent 7b3dd03 commit 284345e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions adjust.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,15 @@ func (f *File) adjustMergeCells(ws *xlsxWorksheet, sheet string, dir adjustDirec
if dir == rows {
if y1 == num && y2 == num && offset < 0 {
f.deleteMergeCell(ws, i)
i--
continue
}

y1, y2 = f.adjustMergeCellsHelper(y1, y2, num, offset)
} else {
if x1 == num && x2 == num && offset < 0 {
f.deleteMergeCell(ws, i)
i--
continue
}

Expand All @@ -644,8 +646,8 @@ func (f *File) adjustMergeCells(ws *xlsxWorksheet, sheet string, dir adjustDirec
}

// adjustMergeCellsHelper provides a function for adjusting merge cells to
// compare and calculate cell reference by the given pivot, operation reference and
// offset.
// compare and calculate cell reference by the given pivot, operation reference
// and offset.
func (f *File) adjustMergeCellsHelper(p1, p2, num, offset int) (int, int) {
if p2 < p1 {
p1, p2 = p2, p1
Expand Down
9 changes: 9 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ func TestRemoveRow(t *testing.T) {
assert.NoError(t, f.RemoveRow(sheet1, 10))
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestRemoveRow.xlsx")))

f = NewFile()
assert.NoError(t, f.MergeCell("Sheet1", "A1", "C1"))
assert.NoError(t, f.MergeCell("Sheet1", "A2", "C2"))
assert.NoError(t, f.RemoveRow("Sheet1", 1))
mergedCells, err := f.GetMergeCells("Sheet1")
assert.NoError(t, err)
assert.Equal(t, "A1", mergedCells[0].GetStartAxis())
assert.Equal(t, "C1", mergedCells[0].GetEndAxis())

// Test remove row on not exist worksheet
assert.EqualError(t, f.RemoveRow("SheetN", 1), "sheet SheetN does not exist")
// Test remove row with invalid sheet name
Expand Down

0 comments on commit 284345e

Please sign in to comment.