Skip to content

Commit a34c81e

Browse files
authored
This closes #1448, speed up for checking merged cells (#1500)
1 parent 478b528 commit a34c81e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cell.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,19 +1388,31 @@ func (f *File) prepareCellStyle(ws *xlsxWorksheet, col, row, style int) int {
13881388
// given cell reference.
13891389
func (f *File) mergeCellsParser(ws *xlsxWorksheet, cell string) (string, error) {
13901390
cell = strings.ToUpper(cell)
1391+
col, row, err := CellNameToCoordinates(cell)
1392+
if err != nil {
1393+
return cell, err
1394+
}
13911395
if ws.MergeCells != nil {
13921396
for i := 0; i < len(ws.MergeCells.Cells); i++ {
13931397
if ws.MergeCells.Cells[i] == nil {
13941398
ws.MergeCells.Cells = append(ws.MergeCells.Cells[:i], ws.MergeCells.Cells[i+1:]...)
13951399
i--
13961400
continue
13971401
}
1398-
ok, err := f.checkCellInRangeRef(cell, ws.MergeCells.Cells[i].Ref)
1399-
if err != nil {
1400-
return cell, err
1402+
if ref := ws.MergeCells.Cells[i].Ref; len(ws.MergeCells.Cells[i].rect) == 0 && ref != "" {
1403+
if strings.Count(ref, ":") != 1 {
1404+
ref += ":" + ref
1405+
}
1406+
rect, err := rangeRefToCoordinates(ref)
1407+
if err != nil {
1408+
return cell, err
1409+
}
1410+
_ = sortCoordinates(rect)
1411+
ws.MergeCells.Cells[i].rect = rect
14011412
}
1402-
if ok {
1413+
if cellInRange([]int{col, row}, ws.MergeCells.Cells[i].rect) {
14031414
cell = strings.Split(ws.MergeCells.Cells[i].Ref, ":")[0]
1415+
break
14041416
}
14051417
}
14061418
}

0 commit comments

Comments
 (0)