如何使用Interop with C#将* .ppt,* .pptx文件保存为* .wmv?

我尝试使用下一个代码执行此操作:

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大小的文件,当然我无法播放它。

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

我找到解决方案:

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

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

尝试

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