How to save *.ppt, *.pptx files as *.wmv using Interop with C#?

馋奶兔 提交于 2019-12-01 08:25:16

问题


I tried to do this with the next code:

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

namespace SavePPT
{
        class Program
        {
            static void Main(string[] args)
            {
                Application app = new PowerPoint.Application();
                var pres = app.Presentations;
                var file = pres.Open(@"C:\Presentation1.pptx", MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
                file.SaveCopyAs(@"C:\presentation1.wmv", PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue);

                app.Quit();

            }
        }
}

But this solution created file with 0 KB size and of course I can't play it.


回答1:


PowerPoint's SaveCopyAs method doesn't appear to support ppSaveAsWMV. It explicitly states which it supports on the MSDN page for SaveCopyAs, which doesn't include the ppSaveAsWMV constant.




回答2:


I find solution:

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

namespace SavePPT
{
        class Program
        {
            static void Main(string[] args)
            {
                string fileName = @"C:\Presentation1.pptx";
                string exportName = "video_of_presentation";
                string exportPath = @"C:\{0}.wmv";

                Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
                ppApp.Visible = MsoTriState.msoTrue;
                ppApp.WindowState = PpWindowState.ppWindowMinimized;
                Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations;
                Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(fileName,
                            MsoTriState.msoFalse, MsoTriState.msoFalse,
                            MsoTriState.msoFalse);
                try
                {
                    oPres.CreateVideo(exportName);
                    oPres.SaveCopyAs(String.Format(exportPath, exportName),
                        PowerPoint.PpSaveAsFileType.ppSaveAsWMV,
                        MsoTriState.msoCTrue);
                }
                finally
                {
                    ppApp.Quit();
                }
            }
        }
}

This code save file, but with some delay. Thanks for help.




回答3:


Try

while (oPres.CreateVideoStatus == PpMediaTaskStatus.ppMediaTaskStatusInProgress)
{
    Thread.Sleep(100);
}


来源:https://stackoverflow.com/questions/13311579/how-to-save-ppt-pptx-files-as-wmv-using-interop-with-c

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