开发者

Export Movies from Powerpoint to file in C#

So开发者_StackOverflow中文版me Powerpoint presentation contains embedded movies. How to export movies from presentation (or get path to movie file) using C# (VSTO or Oficce COM Api)?


Here is simple demo to do this:

don't forget to add reference to the PowerPoint COM API (Microsoft PowerPoint 12.0 Object Library).

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

then you can get the movies path like this

    private void button1_Click(object sender, EventArgs e)
    {
        PowerPoint.Application app = new PowerPoint.Application();
        app.Visible = Office.MsoTriState.msoTrue;
        //open powerpoint file in your hard drive
        app.Presentations.Open(@"e:\my tests\hello world.pptx");

        foreach (PowerPoint.Slide slide in app.ActivePresentation.Slides)
        {
            PowerPoint.Shapes slideShapes = slide.Shapes;
            foreach (PowerPoint.Shape shape in slideShapes)
            {
                if (shape.Type == Office.MsoShapeType.msoMedia &&
                    shape.MediaType == PowerPoint.PpMediaType.ppMediaTypeMovie)
                {
                    //LinkFormat.SourceFullName contains the movie path 
                    //get the path like this
                    listBox1.Items.Add(shape.LinkFormat.SourceFullName);
                    //or use System.IO.File.Copy(shape.LinkFormat.SourceFullName, SOME_DESTINATION) to export them
                }
            }
        }
    }

I hope this will help.

[Edit:]

regarding Steve comment if you want just the embedded movies, you need just to unpack the .pptx file like any other zip file (e.g. using DotNetZip) and look for embedded videos in this path ([PowerPoint_fileName]\ppt\media)


It is very easy. Extract the file as Zip file using SharpZipLib library, the files will be at ppt\media folder :)

this question will help you:

Programmatically extract embedded file from PowerPoint presentation

And this is the link of sharp-zip-lib:

http://www.icsharpcode.net/opensource/sharpziplib/


Checkout the following links

a useful tip to extract .swf file from PowerPoint file

Automation of PowerPoint 97 and PowerPoint 2000 Viewers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜