EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

ParentGroup of ExcelDrawing

Open FedePorti opened this issue 9 months ago • 3 comments

Hi, I have several problems with an excel that has some grouped drawings.

image

I want to access to the drawing inside the group (for example: D2_a_BT, D2_b_BT, etc)

image

I think to access this drawing I would have to do like this (to edit the text of the shape):

sheet1.Drawings.Item("Img_D2_BT").ParentGroup.Drawings.Item("D2_a_BT").As.Shape.Text = "A1"

The problem is that ParentGroup is null.

I also try to UnGroup the shape to edit the child and after Group again, but also I can UnGropup the shape.

image

It seems that epplus takes it as not being grouped.

Also in the imagen you can see that the property Size is null too.

I attached my Excel CalcTF_Amb4.xlsx

FedePorti avatar Apr 29 '24 14:04 FedePorti

It seems like there is a bug when trying to access child drawing via the name. I will add a fix for that. For now, use a linq query or similar...

                var groupDrawing = ((ExcelGroupShape)sheet.Drawings["img_d2_bt"]);
                var childLine1 = groupDrawing.Drawings.FirstOrDefault(x=> x.Name=="D2_Line1_BT");
                 //Instead of...
                 var childLine2 = groupDrawing.Drawings["D2_Line2_BT"];
                 //...Or use the index:
                  var childc = groupDrawing.Drawings[3];

The Size property will be null on drawings that have the EditAs property set to OfficeOpenXml.Drawing.eEditAs.TwoCell Depending on the EditAs property value, you use the properties From, To, Position or Size to get/set the drawings position. The ParentGroup will be set to null for all top-level drawing (in the worksheet.Drawings Collection). Group Drawings (like "D2_Line1_BT"), have the ParentGroup property set to the group drawing that contains it (in this case "img_d2_bt").

JanKallman avatar Apr 30 '24 12:04 JanKallman

Thank you, I use linq and it works. And also works the Size, I already have the property EditAs set to OneCell but after I call the Size (so I move before and it works).

FedePorti avatar Apr 30 '24 13:04 FedePorti

Great, I have added a fix for the Name Indexer issue.

JanKallman avatar May 02 '24 05:05 JanKallman

Fixed in EPPlus 7.1.3

JanKallman avatar May 28 '24 08:05 JanKallman