Optimize setting the value of a cell if the merge state of the cell is known in advance #2303
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The scenario:
I need to copy 1 named range from the template 50,000 (or even more) times into the resulting file
When setting the cell value, the
IsInferiorMergedCell()
method is called, which significantly slows down the speed of operation with a large number of merged ranges. Although if I manually make a merge, I know in advance whether I need to set a value in this cell or notInitially, I thought about making a public method
SetValue(XLCellValue value, bool checkMergedRanges)
, which will avoid this check, but the problem is that the setterFormulaA1
, which is called in theSetValue()
method, also contains theIsInferiorMergedCell()
call.So I decided to just add the
IsInferiorMergedCellUserDefined
property, which will bypass this check. I admit that the solution is not the best, but it suits me. I wanted to highlight the problem more, maybe someone has a better solution right awayCode for reproduce: https://gist.github.com/Arteeck/32de98b54ec85cc9ae923766b73e7562
Template: template.xlsx
Sampling without
IsInferiorMergedCellUserDefined
:Sampling with
IsInferiorMergedCellUserDefined
: