简体   繁体   中英

Export Movies from Powerpoint to file in C#

Some 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 (eg 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM