通过C#从PowerPoint幻灯片创建视频,抛出远程过程调用失败。 (Hresult的例外:0x800706BE)

发布于 2025-01-20 20:37:49 字数 1245 浏览 2 评论 0原文

我有一个 Windows 桌面 C# 应用程序,可以以编程方式将用户的 pptx 导出到 mp4。

我这里有代码:

try
{
    Application application = new Microsoft.Office.Interop.PowerPoint.Application();

    Presentation ppt = application.Presentations.Open("myppt.pptx", MsoTriState.msoFalse,  
    MsoTriState.msoFalse, MsoTriState.msoFalse);

    ppt.CreateVideo("myppt.mp4");

}
catch (Exception ex)
{
    logger.Error(ex.Message);
}

一切正常,并且使用 Powerpoint 2016 和旧版本 Office 365 powerpoint 成功创建了视频。 但是,在我将 Office 365 升级到最新版本 2203 (15028.20160) 后,CreateVideo() 总是失败并抛出异常:“远程过程调用失败”

System.Runtime.InteropServices.COMException (0x800706BE): 遠端程序呼叫失敗。 (發生例外狀況於 HRESULT: 0x800706BE)
於 Microsoft.Office.Interop.PowerPoint._Presentation.CreateVideo(String FileName, Boolean UseTimingsAndNarrations, Int32 DefaultSlideDuration, Int32 VertResolution, Int32 FramesPerSecond, Int32 Quality) 

我也尝试过Presentation.SaveCopyAs(...) 和Presentation.Slides[x]。 Export(...) 和这些函数工作正常。

任何帮助将不胜感激。

更新:

如果将“WithWindow”参数设置为 true,则 CreateVideo() 可以工作 演示文稿 ppt = application.Presentations.Open("myppt.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue)

但我不知道原因...

I have a Windows desktop C# app which is to export user's pptx to mp4 programmatically.

I have code here:

try
{
    Application application = new Microsoft.Office.Interop.PowerPoint.Application();

    Presentation ppt = application.Presentations.Open("myppt.pptx", MsoTriState.msoFalse,  
    MsoTriState.msoFalse, MsoTriState.msoFalse);

    ppt.CreateVideo("myppt.mp4");

}
catch (Exception ex)
{
    logger.Error(ex.Message);
}

Everything works fine and video is created successfully with Powerpoint 2016 and older version Office 365 powerpoint.
However after I upgraded Office 365 to latest version 2203 (15028.20160), CreateVideo() always failed and throws exception: "The remote procedure call failed"

System.Runtime.InteropServices.COMException (0x800706BE): 遠端程序呼叫失敗。 (發生例外狀況於 HRESULT: 0x800706BE)
於 Microsoft.Office.Interop.PowerPoint._Presentation.CreateVideo(String FileName, Boolean UseTimingsAndNarrations, Int32 DefaultSlideDuration, Int32 VertResolution, Int32 FramesPerSecond, Int32 Quality) 

I have also tried Presentation.SaveCopyAs(...) and Presentation.Slides[x].Export(...) and these functions work fine.

Any help would be appreciated.

Update:

CreateVideo() works if set "WithWindow" parameter to true in
Presentation ppt = application.Presentations.Open("myppt.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue)

But I don't know the reason...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娇女薄笑 2025-01-27 20:37:49

使用Office部署工具返回到先前的Office版本,在该版本中,您根据工作的长期行为。他们在第2203号版本中将其弄坏了,因此回到2202或更早的时间将修复它。

config.xml文件工作:

<Configuration>
  <Updates Enabled="TRUE" TargetVersion="16.0.14931.20132"/>
</Configuration>

Use the Office Deployment Tool to roll back to a prior version of Office where the long-established behavior you're depending on worked. They broke it in release 2203, so rolling back to 2202 or earlier will fix it.

This config.xml file works:

<Configuration>
  <Updates Enabled="TRUE" TargetVersion="16.0.14931.20132"/>
</Configuration>
星星的軌跡 2025-01-27 20:37:49

System.Runtime.InteropServices.COMException(0x800706BE)

此异常通常表示您尝试从 Web 服务或 ASP.NET 应用程序自动化 PowerPoint。

Office 服务器端自动化的注意事项一文针对该场景指出了以下内容:

Microsoft 目前不建议也不支持通过任何无人值守、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)实现 Microsoft Office 应用程序的自动化,因为 Office 可能会表现出不稳定的情况在此环境中运行 Office 时的行为和/或死锁。

如果您正在构建在服务器端上下文中运行的解决方案,则应尝试使用可安全执行无人值守执行的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方案。如果您使用服务器端解决方案中的 Office 应用程序,该应用程序将缺乏许多成功运行所需的功能。此外,您还将面临整体解决方案稳定性的风险。

您可以考虑使用Open XML SDK如果您处理开放的 XML 文档或考虑使用为服务器端执行而设计的第三方组件。

System.Runtime.InteropServices.COMException (0x800706BE)

This exception typically indicates that you trying to automate PowerPoint from a web service or ASP.NET application.

The Considerations for server-side Automation of Office article states the following for that scenario:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

You may consider using the Open XML SDK if you deal with open XML documents or consider using third-party components designed for the server-side execution.

岁月染过的梦 2025-01-27 20:37:49

如果您的应用不依赖MS Office,那会更好。 aspose.spose.slides cloud sdk for .net 可以提供这样的要求。它不需要安装PowerPoint。该产品为演示处理提供了基于REST的API。这是一种付费产品,但是您可以每月拨打150个免费的API呼叫,以进行实验,学习和任何其他目的。

以下代码示例向您展示了如何使用aspose.net的云SDK将演示文稿转换为视频文件:

var slidesApi = new SlidesApi("my_client_id", "my_client_secret");

// Set options for the output video.
var videoOptions = new VideoExportOptions
{
    VideoResolutionType = VideoExportOptions.VideoResolutionTypeEnum.FullHD
};

// Convert a presentation file to a video file.
using var presentationStream = File.OpenRead("example.pptx");
using var videoStream = slidesApi.Convert(presentationStream, ExportFormat.Mpeg4, options: videoOptions);

// Save the result to a file.
using var outputStream = File.Create("output.mp4");
videoStream.CopyTo(outputStream);

有时有必要将演示文稿转换为没有任何代码的视频。对于这种情况,您可以使用免费 powerpoint到视频转换器

我在Aspose担任支持开发人员。

It would be better if your app did not depend on MS Office. Aspose.Slides Cloud SDK for .NET can provide such a requirement. It does not require PowerPoint installed. This product provides a REST-based API for presentation processing. It is a paid product, but you can make 150 free API calls per month for experimentation, learning, and any other purpose.

The following code example shows you how to convert a presentation to a video file using Aspose.Slides Cloud SDK for .NET:

var slidesApi = new SlidesApi("my_client_id", "my_client_secret");

// Set options for the output video.
var videoOptions = new VideoExportOptions
{
    VideoResolutionType = VideoExportOptions.VideoResolutionTypeEnum.FullHD
};

// Convert a presentation file to a video file.
using var presentationStream = File.OpenRead("example.pptx");
using var videoStream = slidesApi.Convert(presentationStream, ExportFormat.Mpeg4, options: videoOptions);

// Save the result to a file.
using var outputStream = File.Create("output.mp4");
videoStream.CopyTo(outputStream);

Sometimes it is necessary to convert presentations to videos without any code. For such cases, you can use a free PowerPoint to Video Converter.

I work as a Support Developer at Aspose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文