3

我试图用下面的代码做到这一点:

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

            }
        }
}

但是这个解决方案创建了 0 KB 大小的文件,当然我不能播放它。

4

3 回答 3

3

我找到解决方案:

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

此代码保存文件,但有一些延迟。感谢帮助。

于 2012-11-12T08:19:46.657 回答
2

尝试

while (oPres.CreateVideoStatus == PpMediaTaskStatus.ppMediaTaskStatusInProgress)
{
    Thread.Sleep(100);
}
于 2013-12-30T18:14:10.950 回答
0

PowerPoint 的 SaveCopyAs 方法似乎不支持 ppSaveAsWMV。它在MSDN 页面上明确说明了它支持的SaveCopyAs,其中不包括 ppSaveAsWMV 常量。

于 2012-11-09T16:14:59.920 回答