Skip to content

Commit

Permalink
This closes qax-os#1448, speed up for checking merged cells (qax-os#1500
Browse files Browse the repository at this point in the history
)
  • Loading branch information
CHANTXU64 authored Mar 20, 2023
1 parent 7e4a9e3 commit bd29b87
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -1388,19 +1388,31 @@ 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 {
ws.MergeCells.Cells = append(ws.MergeCells.Cells[:i], ws.MergeCells.Cells[i+1:]...)
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
}
}
}
Expand Down

0 comments on commit bd29b87

Please sign in to comment.