我尝试使用下一个代码执行此操作:
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大小的文件,当然我无法播放它。
答案 0 :(得分: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();
}
}
}
}
此代码保存文件,但有一些延迟。谢谢你的帮助。
答案 1 :(得分:1)
尝试
while (oPres.CreateVideoStatus == PpMediaTaskStatus.ppMediaTaskStatusInProgress)
{
Thread.Sleep(100);
}
答案 2 :(得分:0)
PowerPoint的SaveCopyAs方法似乎不支持ppSaveAsWMV。它明确说明它支持SaveCopyAs的MSDN page,它不包含ppSaveAsWMV常量。