Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1448 Enhances the performance of checkCellInRangeRef and merging cells. #1500

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

CHANTXU64
Copy link
Contributor

@CHANTXU64 CHANTXU64 commented Mar 19, 2023

PR Details

Enhances the performance of checkCellInRangeRef and merging cells.

Description

Enhances the performance of checkCellInRangeRef and merging cells.

Related Issue

Slow Performance when there are lots of merge cells & calculations #1448

Motivation and Context

Slow Performance when there are lots of merge cells & calculations #1448

How Has This Been Tested

run go test

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@xuri xuri added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 19, 2023
Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR. Using the rect fields of merged cell in the mergeCellsParser function instead of add cache:

diff --git a/cell.go b/cell.go
index a23296b..20400f6 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
            }
        }
    }

@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2023

Codecov Report

Merging #1500 (32154a4) into master (7631fd0) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #1500      +/-   ##
==========================================
- Coverage   98.69%   98.65%   -0.04%     
==========================================
  Files          31       31              
  Lines       24332    24344      +12     
==========================================
+ Hits        24014    24017       +3     
- Misses        210      216       +6     
- Partials      108      111       +3     
Flag Coverage Δ
unittests 98.65% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cell.go 98.01% <100.00%> (-0.99%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Enhances the performance of checkCellInRangeRef and merging cells.
Copy link
Contributor Author

@CHANTXU64 CHANTXU64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution. I have made some changes based on your branch. This patch will be released in the next version.

@xuri xuri merged commit a34c81e into qax-os:master Mar 20, 2023
@xuri xuri added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 20, 2023
fudali113 pushed a commit to fudali113/excelize that referenced this pull request Apr 17, 2023
xuri pushed a commit to JDavidVR/excelize that referenced this pull request Jul 11, 2023
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this pull request Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants