c# - 如何使用 Interop 和 C# 将 *.ppt、*.pptx 文件保存为 *.wmv?

标签 c# .net interop powerpoint 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 大小的文件,当然我不能播放它。

最佳答案

我找到了解决方案:

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

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

关于c# - 如何使用 Interop 和 C# 将 *.ppt、*.pptx 文件保存为 *.wmv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13311579/

相关文章:

c# - 如何在对象上进行交易

c# - c# 和 vb,net 中的奇怪行为或 ^ 运算符

c++ - 将 C++/CLI 字符串数组转换为 native C++ 字符**

.net - 如何使用缩写的时区显示 DateTime?

c# - 从 WinForms 窗体显示 WPF 窗口绝对安全吗?

Java/C# Kerberos 互操作可能吗?

c# - WebTestRequest.ReportingName 在使用 VS 团队服务时被忽略

c# - 将 CSV 文件转换为 XML

c# - 如何在整数数据类型变量中将sql参数作为空值传递?

.net - 如何在安全站点中使用 webclient?