How to save *.ppt, *.pptx files as *.wmv using Interop with C#?

前端 未结 3 1819
Happy的楠姐
Happy的楠姐 2021-01-14 14:29

I tried to do this with the next code:

using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using System.IO;
using Microsoft         


        
相关标签:
3条回答
  • 2021-01-14 15:03

    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.

    0 讨论(0)
  • 2021-01-14 15:14

    Try

    while (oPres.CreateVideoStatus == PpMediaTaskStatus.ppMediaTaskStatusInProgress)
    {
        Thread.Sleep(100);
    }
    
    0 讨论(0)
  • 2021-01-14 15:26

    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.

    0 讨论(0)
提交回复
热议问题