【问题标题】:Powerpoint interopPowerpoint 互操作
【发布时间】:2016-01-06 05:20:59
【问题描述】:

我是 .NET 新手。我想制作一个将 .pptx 文件转换为 .wmv 的控制台应用程序。我已经设法使用 powerpoint interop 来做到这一点。但是我有一些问题。首先,如果我构建应用程序并将其转移到另一台计算机上,我会得到一个已为 COM 对象返回异常错误 HRESULT E_FAIL(我在两台 PC 中都有 powerpoint)。如果我在我写的那个上运行它,我一切正常。但不是第一次。这意味着当我启动我的 pc 和运行它我会得到同样的异常,第二次我会尝试运行它会正常运行。可能是什么问题?iguess with interop and powerpoint 但我想不通。

好的,代码如下:

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

  namespace Microsoft.Office.Interop.PowerPoint
 {
  class Program
  {

    static void Main(string[] args)
    {

        string fileName = args[0];
        string exportName = args[1];
        string exportPath = args[2];

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

}
}

【问题讨论】:

  • 这个问题没有更多的细节是无法回答的,恐怕......你如何尝试执行PPT?两台机器上的操作系统是否相同?等等。
  • 很可能某些 COM 最初没有加载,因此在您第二次加载它时它会崩溃,所以没有错误

标签: interop powerpoint


【解决方案1】:

_Presentation.CreateVideo 不会根据 powerpoint 创建视频。它在一个幻灯片创建一个视频。无论如何,这就是documentation says

尝试_Presentation.SaveAs,然后使用PpSaveAsFileType.ppSaveAsWMV 作为文件类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多