Dynamically add image to openxml PowerPoint

I am creating Power Point 2007 files using openxml. I can add slides, shapes, text and manipulate them to create custom reports. However, I cannot find an example of how to dynamically upload an image to my power points. Basically, I assume that this involves adding an image as a resource, and then adding a link to that resource. Any sample code would be a big help.

Thanks.

+6
source share
1 answer

First you need to add ImagePart to your SlidePart as follows:

ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, "rId3"); 

"rId3" should be a ratio that matches your image that you are adding to the presentation. You can also leave this parameter blank and a default relationship identifier will be created for you. Then you need to transfer this part of the image to the actual image:

 imagePart.FeedData(new MemoryStream(photo.ToArray())); 

If you still have problems, take a look at these two blog posts. Both of them show some code in the middle of the path about adding photos to the presentation.

Creating a report presentation based on data

Add duplicate data to PowerPoint

+5
source

Source: https://habr.com/ru/post/888369/


All Articles