-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fixed drawingResize dimensions calculation #2123
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your pull request. I've left some comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The image will overflow Sheet1!B30
cell after this changes, the image with AutoFit
inserted by this unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Sheet2!I9
cell image has been affected (the ratio of width to height increases), the image is widened after this changes. The image inserted by this unit test.
I fear that this is a very complex subject which needs to be discussed, please hear me out. First of all I just realized another issue of the current implementation and fork (at least from my point of view). If I understand you correctly you suggest, that AutoFit should add pictures into the target cell and resize the image in a way, that it is not rendered beyond the cell borders. However the current implementation changes the from anchor if the offset leaves the area of the cell. This means that a cell insertion targeting A1 can end up starting in A2. While the initial visible result seems to be correct there is an issue: The image will be moved if Cell A1 is being enlarged. This is not correct and I think that I should fix this as well. The starting anchor point can be outside of the cell dimensions which leads to correct anchoring and simply hides the image as long as the cell is not expanded enough. In the end this will still break your expectation, but just in another way. AutoFit would resize the image respecting the aspect ratio to the current cell dimensions and if an offset is used which causes the image to overflow the cell, it would look cut off, but this could be changed by the user, by expading the row / col size. However, from my understanding your expected behaviour comes along with various problematic edge cases and this is why I would like to suggest considering to review this feature:
Otherwise another option like "ResizeToCell" would be required or even target size fields for the picture struct. What are your thoughts about this? |
Yes, I agree with you, offsets shouldn't affect the image size. Users using AutoFit with Offset will be affected after these changes, like user case in #1560, I accept this, we can make these changes as a breaking change and notice user in release notes. |
Any update for other remaining code review issues? |
Im working on it hoping to complete it today, from what I have noticed the anchoring wasnt fully correct and confused me a bit. |
@xuri I think its finally done Some explanations:
Please notice regarding the anchoring behaviour: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After these changes, add 60px x 60px image to test issue #2001, the size of the last 3 images is incorrect.
You can download this image attachment:
The result:

I will try to reproduce this issue and add a test case for it 👍 (Propably on monday) |
Please set the target branch to master instead of v2. Create branch from master. |
I fixed the absolute anchoring issue - the issue arised from updating the anchors since oneCellAnchors have absolute sizes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your update. I test issue #2001, all the size of the images is correct, but the position of the last image is incorrect. If the value of OffsetX
and OffsetY
is over than anchor cell column width or height, it won't work.

Expected:

Hopefully this covers all your questions or issues: If we are talking about oneCellAnchors, Excel starts overlapping images from last to first if the images do not fit into the column. This can be observed by resizing the column. Implementing an overflow by hand creates other issues like I have mentioned earlier (image separation; incorrect anchor cell, which causes unexpected movements on column resizing/hiding). At least currently I do not know about a property or similar to control or override this behavior of excel regarding too many images for column size X. Does this answer your question or did I miss something? |
- Shorten parameters for the positionObjectPixels function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The positionObjectPixels
function has too many parameters, I pushed a commit on your branch, combine some parameters to made it shorten and simplicity.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2123 +/- ##
========================================
Coverage 99.22% 99.23%
========================================
Files 32 32
Lines 30114 30222 +108
========================================
+ Hits 29882 29991 +109
+ Misses 154 153 -1
Partials 78 78
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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.
PR Details
The current implementation does not seem to be in accordance to the specification:
https://github.com/closedxml/closedxml/wiki/Cell-Dimensions
https://github.com/closedxml/closedxml/wiki/Cell-Dimensions#mdw
https://github.com/closedxml/closedxml/wiki/Cell-Dimensions#skiasharp-code
Also there seem to be logical issues as well. This commit solves an identical issue as linked below.
Description
Looking at the C# ClosedXML Excel file Wiki:
Related Issue
#2001
Motivation and Context
In my use case I encountered the problems mentioned in the issue #2001 and these changes applied locally fixed my issues.
How Has This Been Tested
Try to add multiple images into a single cell using offsets as mentioned in #2001. Currently this will cause problems. Like mentioned earlier these changes solve these issues.
Types of changes
Checklist