diff options
author | xuri <xuri.me@gmail.com> | 2019-06-12 08:10:33 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2019-06-12 08:10:33 +0800 |
commit | 821632cf89422b9955160a3af7f28f05a12f70f8 (patch) | |
tree | 78ed9fa1fcbee8b78bd1a396e3307f97ac38926e /cell.go | |
parent | 46a3632ee0f441c8990a7205445dfdb00823a6ad (diff) |
Fix #424, refactor merged cells adjuster
Diffstat (limited to 'cell.go')
-rw-r--r-- | cell.go | 22 |
1 files changed, 9 insertions, 13 deletions
@@ -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 { |