From a34c81e1ccbfdfa082fe63d6fa0f68510a4ba725 Mon Sep 17 00:00:00 2001 From: ChantXu64 Date: Mon, 20 Mar 2023 09:17:28 +0800 Subject: [PATCH] This closes #1448, speed up for checking merged cells (#1500) --- cell.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cell.go b/cell.go index a23296b6..3fdbea96 100644 --- a/cell.go +++ b/cell.go @@ -1388,6 +1388,10 @@ func (f *File) prepareCellStyle(ws *xlsxWorksheet, col, row, style int) int { // given cell reference. func (f *File) mergeCellsParser(ws *xlsxWorksheet, cell string) (string, error) { cell = strings.ToUpper(cell) + col, row, err := CellNameToCoordinates(cell) + if err != nil { + return cell, err + } if ws.MergeCells != nil { for i := 0; i < len(ws.MergeCells.Cells); i++ { if ws.MergeCells.Cells[i] == nil { @@ -1395,12 +1399,20 @@ func (f *File) mergeCellsParser(ws *xlsxWorksheet, cell string) (string, error) i-- continue } - ok, err := f.checkCellInRangeRef(cell, ws.MergeCells.Cells[i].Ref) - if err != nil { - return cell, err + if ref := ws.MergeCells.Cells[i].Ref; len(ws.MergeCells.Cells[i].rect) == 0 && ref != "" { + if strings.Count(ref, ":") != 1 { + ref += ":" + ref + } + rect, err := rangeRefToCoordinates(ref) + if err != nil { + return cell, err + } + _ = sortCoordinates(rect) + ws.MergeCells.Cells[i].rect = rect } - if ok { + if cellInRange([]int{col, row}, ws.MergeCells.Cells[i].rect) { cell = strings.Split(ws.MergeCells.Cells[i].Ref, ":")[0] + break } } }