I'm converting a PowerPoint presentation ( .ppt
) into a .wmv
video file using this code:
static void Main(string[] args)
{
string fileName = @"D:\example1.pptx";
string exportName = "video_of_presentation";
string exportPath = @"D:\{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();
}
}
It's work great. Now I'm trying to convert a single slide from this presentation into video file. I tried to use this:
var i = 0;
foreach (var slide in oPres.Slides)
{
slide.CreateVideo(string.Format("slide{0}", i));
i++;
}
But it seems that slide hasn't CreateVideo
method.
I think that I need to create a new presentation every iteration and add a slide into it, but I can't understand how to add a slide from my presentation to a new presentation.
I tried this code:
Presentation singleSlidePpt = ppApp.Presentations.Add(MsoTriState.msoTrue);
singleSlidePpt.Slides.Add(oPres.Slides[0], CustomLayout);
Any suggesions how to solve this problem?
Save the presentation to a new name then delete all of the slides you DON'T need.
Be sure to do it in reverse order, else you'll get the wrong results.
If you want to convert a PPT to video, PowerPoint itself has this function "create video".
But I don't know whether it can convert to .wmv
video directly. If not, you can use a converter after PPT is converted into video, although it seems not the simplest way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.