C# Save PPT Shape (msoPicture) as Image w/ Office.Interop

六月ゝ 毕业季﹏ 提交于 2019-12-12 03:57:45

问题


I have a PPT slide deck with multiple images. I am iterating through each slide and each shape. I would like to save each shape of type msoPicture as an Image:

            foreach (PPT.Slide slide in pptDoc.Slides)
            {
                foreach (PPT.Shape shape in slide.Shapes)
                {
                    if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
                    {

                        Image img;
                        //???? Save shape as image
                        img.Save(filename);
                    }
                }
            }

回答1:


You can use the Shape.Export() method to create an image from an individual shape.

For example like this:

foreach (PPT.Slide slide in pptDoc.Slides)
{
    foreach (PPT.Shape shape in slide.Shapes)
    {
        if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
        {
            shape.Export(filename, Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG);
        }
    }
}


来源:https://stackoverflow.com/questions/42442659/c-sharp-save-ppt-shape-msopicture-as-image-w-office-interop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!