在 C# 中将电影从 Powerpoint 导出到文件

发布于 2024-10-17 10:17:28 字数 87 浏览 1 评论 0原文

某些 Powerpoint 演示文稿包含嵌入的电影。 如何使用 C#(VSTO 或 Oficce COM Api)从演示文稿中导出电影(或获取电影文件的路径)?

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

锦上情书 2024-10-24 10:17:28

这是执行此操作的简单演示:

不要忘记添加对 PowerPoint COM API 的引用
(Microsoft PowerPoint 12.0 对象库)。

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

然后你就可以像这样获取电影路径

    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
                }
            }
        }
    }

我希望这会有所帮助。

[编辑:]

关于 Steve 的评论,如果您只想要嵌入的电影,您只需像任何其他 zip 文件一样解压 .pptx 文件(例如使用 DotNetZip)并在此路径中查找嵌入视频( [PowerPoint_文件名]\ppt\media)

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)

岁月静好 2024-10-24 10:17:28

这很容易。使用 SharpZipLib 库将文件提取为 Zip 文件,文件将位于 ppt\media 文件夹:)

这个问题将帮助您:

以编程方式从 PowerPoint 演示文稿中提取嵌入文件

这是 Sharp-zip-lib 的链接:

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文