I am creating power point 2007 files using the openxml. I am able to add slides, shapes, text and 开发者_如何转开发manipulate them to create custom reports. However, I can not find an example on how to dynamically load an image into my power points. In principle I imagine that it would involve adding the image as a resource and then adding a reference to that resource. Any example code would be great help.
Thank you.
You will first need to add an ImagePart to your SlidePart like this:
ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Png, "rId3");
The "rId3"
needs to be the relationshipId that corresponds to your image that you are adding to the presentation. You could also leave that parameter blank and a default relationship id will be created for you. Next you need to feed that image part the actual image:
imagePart.FeedData(new MemoryStream(photo.ToArray()));
If you are still having trouble take a look at these two blog posts. They both show some code mid way down about adding photos to a presentation.
Creating a report presentation based on data
Adding repeating data to PowerPoint
精彩评论