summaryrefslogtreecommitdiff
path: root/cell.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2019-06-12 08:10:33 +0800
committerxuri <xuri.me@gmail.com>2019-06-12 08:10:33 +0800
commit821632cf89422b9955160a3af7f28f05a12f70f8 (patch)
tree78ed9fa1fcbee8b78bd1a396e3307f97ac38926e /cell.go
parent46a3632ee0f441c8990a7205445dfdb00823a6ad (diff)
Fix #424, refactor merged cells adjuster
Diffstat (limited to 'cell.go')
-rw-r--r--cell.go22
1 files changed, 9 insertions, 13 deletions
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 {