i have a powerpoint file with a textbox (or any other component) and i would like to move it to the other side of the slide. i wrote a simple function but it's not yielding the expected results.
i attached a zip file an image to explain the formula i came up with to do this as shown in my code, and the test file
please advise
private void MoveObject(IShape ishp, double width)
{
if (ishp.SlideItemType is SlideItemType.Chart) ; //do something
else if (ishp.SlideItemType is SlideItemType.Table) ; //do something
else if (ishp.SlideItemType is SlideItemType.Picture)
ishp.Left = width - (ishp.Left + ishp.Width);
else if (ishp.SlideItemType is SlideItemType.GroupShape)
{
IGroupShape groupShape = ishp as IGroupShape;
foreach (IShape childShape in groupShape.Shapes)
MoveObject(childShape, width);
}
else if (ishp.SlideItemType is SlideItemType.AutoShape)
ishp.Left = width - (ishp.Left + ishp.Width);
}
Hi omar,
Yes. It is feasible to move the shapes to the
other side of the slide as per your requirement using Syncfusion Presentation
library.
On further analysis the given PowerPoint Presentation, most of the shapes are multiple
nested group shapes. Your code logic to move shapes to the left is not suitable
for the child shapes inside the group shape in the given PowerPoint. Because the
left value of the child shapes is calculated based on the group shape bounds.
So, to resolve this problem, we suggest you to ungroup all the group shapes in
your input PowerPoint document in the Microsoft PowerPoint application and then
move shapes to left as per your logic using the Syncfusion Presentation
library.
Also, we have found some textbox shapes having different right and left margin
values. So need to shift the margin values for that shape while move to the
left like a mirror.
We have prepared the sample application to move
the shapes using the modified input PowerPoint (Ungroup) and it can be
downloaded from the below attachment.
Regards,
Suriya Balamurugan.
hello!
On further analysis the given PowerPoint Presentation, most of the shapes are multiple nested group shapes. Your code logic to move shapes to the left is not suitable for the child shapes inside the group shape in the given PowerPoint. Because the left value of the child shapes is calculated based on the group shape bounds.
This explains the wierd/wrong result when I ran your code against a new sample file of 3 slides. How do I ungroup? Didn't find any related method in the GroupShape class. Maybe under a different name? Attached zip file has test 1 and test 1 result pptx files
Also, we have found some textbox shapes having different right and left margin values. So need to shift the margin values for that shape while move to the left like a mirror.
I ran your code against a new sample of 4 slides. System.ArgumentException: 'Invalid Margin Left' was caused at the line ishp.TextBody.MarginLeft = ishp.TextBody.MarginRight; for each of those slides. Attached zip file has test 2 pptx file. Btw, running the above sample (test 1.pptx) against this code didn't produce this exception.
Attachment: test_1_2_acac5da.zip
This is the right code to traverse through nested groupshapes. With this part, I am now confident that i can go through all the shapes in the slides
private void MoveObject(int slideNumber, ISlideItem isl)
{
if (isl.SlideItemType == SlideItemType.GroupShape)
{
IGroupShape igs = isl as IGroupShape;
for (int i = 0; i < igs.Shapes.Count; i++)
MoveObject(slideNumber, igs.Shapes[i]);
}
}
Hi omar,
Currently we are trying to reproduce the reported problem and we will share the
further details on 26th October 2022.
Regards,
Suriya Balamurugan.
Hi omar,
Please find the details below,
Queries |
Details |
This explains the wierd/wrong result when I ran your code against a new sample file of 3 slides. How do I ungroup? Didn't find any related method in the GroupShape class. Maybe under a different name? Attached zip file has test 1 and test 1 result pptx files |
Currently
Essential Presentation does not provide “API
to Ungroup shapes in the PowerPoint Presentation”. We don’t have any
immediate plans to implement this feature. |
I ran your code against a new sample of 4 slides. System.ArgumentException: 'Invalid Margin Left' was caused at the line ishp.TextBody.MarginLeft = ishp.TextBody.MarginRight; for each of those slides. Attached zip file has test 2 pptx file. Btw, running the above sample (test 1.pptx) against this code didn't produce this exception. |
This exception is due to the sample level code changes in our provided sample in our previous post. We have modified the sample application to resolve the exception and it can be downloaded from the below attachment. |
how do you ungroup programatically? if there is no such method in your library, this means i'll have to create a copy of the powerpoint file, move everything IN the groupshapes to it and keep track of that, and then in that new file, i'll do the mirror movement part and then i'll group the shapes again. or is there another workaround for this? |
To achieve your requirement, if you have group
shape means, you need to ungroup. But currently Essential Presentation does not provide “API to
Ungroup shapes in the PowerPoint Presentation”. We don’t have any
immediate plans to implement this feature. |
i still don't understand the left margin exception as mentioned in the previous post |
As mentioned earlier, this exception is due to the sample level code changes in our provided sample in our previous post. We have modified the sample application to resolve the exception and it can be downloaded from the below attachment. |
it is not my intention to double post but i didn't knwo if it's okay to write my progress in a separate post or if i should have just edited the previous post. sorry. please advise for next time |
You can edit your previous post until we reply
to your new post. Otherwise, write your progress in separate post. |
Regards,
Suriya Balamurugan.
thank you very much for the reply. I'm going to compare your first version to the second version to better understand the changes.
i especially am thankful for letting me know when you're going to reply. i think you should do that all the time. at least we would know when to expect a response instead of a big ? hanging in the air :D
i'll come back here later tomorrow and mark this as answered if i'm done.