From 821632cf89422b9955160a3af7f28f05a12f70f8 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 12 Jun 2019 08:10:33 +0800 Subject: Fix #424, refactor merged cells adjuster --- cell.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'cell.go') diff --git a/cell.go b/cell.go index bd4d93b..6743e2a 100644 --- a/cell.go +++ b/cell.go @@ -401,31 +401,27 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error { // If you create a merged cell that overlaps with another existing merged cell, // those merged cells that already exist will be removed. func (f *File) MergeCell(sheet, hcell, vcell string) error { - hcol, hrow, err := CellNameToCoordinates(hcell) + coordinates, err := f.areaRefToCoordinates(hcell + ":" + vcell) if err != nil { return err } + x1, y1, x2, y2 := coordinates[0], coordinates[1], coordinates[2], coordinates[3] - vcol, vrow, err := CellNameToCoordinates(vcell) - if err != nil { - return err - } - - if hcol == vcol && hrow == vrow { + if x1 == x2 && y1 == y2 { return err } // Correct the coordinate area, such correct C1:B3 to B1:C3. - if vcol < hcol { - hcol, vcol = vcol, hcol + if x2 < x1 { + x1, x2 = x2, x1 } - if vrow < hrow { - hrow, vrow = vrow, hrow + if y2 < y1 { + y1, y2 = y2, y1 } - hcell, _ = CoordinatesToCellName(hcol, hrow) - vcell, _ = CoordinatesToCellName(vcol, vrow) + hcell, _ = CoordinatesToCellName(x1, y1) + vcell, _ = CoordinatesToCellName(x2, y2) xlsx, err := f.workSheetReader(sheet) if err != nil { -- cgit v1.2.1