-->

How to save *.ppt, *.pptx files as *.wmv using Int

2019-02-19 13:36发布

问题:

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