This closes #1448, speed up for checking merged cells (#1500)

This commit is contained in:
ChantXu64 2023-03-20 09:17:28 +08:00 committed by GitHub
parent 478b528af1
commit a34c81e1cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

16
cell.go
View File

@ -1388,6 +1388,10 @@ func (f *File) prepareCellStyle(ws *xlsxWorksheet, col, row, style int) int {
// given cell reference. // given cell reference.
func (f *File) mergeCellsParser(ws *xlsxWorksheet, cell string) (string, error) { func (f *File) mergeCellsParser(ws *xlsxWorksheet, cell string) (string, error) {
cell = strings.ToUpper(cell) cell = strings.ToUpper(cell)
col, row, err := CellNameToCoordinates(cell)
if err != nil {
return cell, err
}
if ws.MergeCells != nil { if ws.MergeCells != nil {
for i := 0; i < len(ws.MergeCells.Cells); i++ { for i := 0; i < len(ws.MergeCells.Cells); i++ {
if ws.MergeCells.Cells[i] == nil { if ws.MergeCells.Cells[i] == nil {
@ -1395,12 +1399,20 @@ func (f *File) mergeCellsParser(ws *xlsxWorksheet, cell string) (string, error)
i-- i--
continue continue
} }
ok, err := f.checkCellInRangeRef(cell, ws.MergeCells.Cells[i].Ref) 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 { if err != nil {
return cell, err return cell, err
} }
if ok { _ = sortCoordinates(rect)
ws.MergeCells.Cells[i].rect = rect
}
if cellInRange([]int{col, row}, ws.MergeCells.Cells[i].rect) {
cell = strings.Split(ws.MergeCells.Cells[i].Ref, ":")[0] cell = strings.Split(ws.MergeCells.Cells[i].Ref, ":")[0]
break
} }
} }
} }