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

Make the properties of width and height in the ExcelDrawing class #1014

Open
FedePorti opened this issue Aug 15, 2023 · 4 comments
Open

Make the properties of width and height in the ExcelDrawing class #1014

FedePorti opened this issue Aug 15, 2023 · 4 comments
Assignees

Comments

@FedePorti
Copy link

I have a excel template like this:
image
And I want to set the position of one of these images in the red rectangle. The images can have different sizes, but the width of the column is constant, so if I can know the width and height (implement the properties of these variables) of the drawing I can do this.

Or there is another way to to this?

@JanKallman
Copy link
Contributor

Depending on the type Anchor type (the EditAs property) of you can use the From, To, Position and Size properties for sizing and positioning. For grouped drawings I think you should use Position and Size.
You can also use the SetPosition and SetSize Methods, but it might not work if you want to preserve the width.
Playing with these properties directly you might need to set the "ExcelPackage.DoAdjustDrawings" to false.

@FedePorti
Copy link
Author

FedePorti commented Aug 17, 2023

Thanks you. After your comments I tried and could solve the problem with this:

.Drawings.Item(aux).ChangeCellAnchor(eEditAs.OneCell) 'with this line now property Size is not null anymore (and I can access to the width of the imagen)
Dim ColOffset As Integer = (360 - .Drawings.Item(aux).Size.Width / 9525) / 2
Dim Col As Integer = Int(ColOffset / 40) 'integer columns where the draw should start
ColOffset = ColOffset - 40 * Col 'each column is 40 pixels
.Drawings.Item(aux).SetPosition(21, 10, 20 + Col, ColOffset) 'the initial row is 21 and the initial column is 20, row height is 20 pixels

The only thing I noticed is that the inputs RowOffsetPixels and ColumnOffsetPixels of the function SetPosition if they are negative and grater than the row height or column width, they can be in a row less than the initial row or column. But If they are positive and grater than the row height or column width, they only go to the inital row +1 and initial column +1.

@JanKallman
Copy link
Contributor

You can also use the From and Two properties for coordinates when the cell anchor is set to TwoCell.

@FedePorti
Copy link
Author

Yes but when I tried to use From and To combined with ExcelPackage.DoAdjustDrawings = false and OneCell, the drawing change the size.
I tried like this:
.Drawings.Item(aux).EditAs = eEditAs.OneCell
.Drawings.Item(aux).From.Row = 21
.Drawings.Item(aux).From.Column = 20
.Drawings.Item(aux).To.Row = 28
.Drawings.Item(aux).To.Column = 29

And the result was like this:
image

The size of the imagen change. My idea was to be in that area without changing the size and to be in the middle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants