简体   繁体   English

打开 powerpoint 演示文稿并隐藏 window

[英]Open a powerpoint presentation and hide the window

I am trying to open a PowerPoint presentation, and have it hidden.我正在尝试打开一个 PowerPoint 演示文稿,并将其隐藏。 I am doing it this way:我这样做:

app = new Microsoft.Office.Interop.PowerPoint.Application();
string presentation = "C:\\presentation.pptx";

Presentation p = app.Presentations.Open(presentation, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

It is the simplest thing, yet I receive an error saying:这是最简单的事情,但我收到一条错误消息:

Application (unknown member): Invalid request.应用程序(未知成员):无效请求。 There is no active presentation.没有活动演示文稿。

However, if I switch the last parameter (which is the WithWindow parameter) to MsoTriState.msoTrue , the presentation opens fine.但是,如果我将最后一个参数(即 WithWindow 参数)切换为MsoTriState.msoTrue ,则演示文稿可以正常打开。

Do you have any other add-ins that might be causing that error? 您还有其他可能导致该错误的加载项吗? I ran your code (from VBA) and it ran fine. 我运行了您的代码(来自VBA),并且运行良好。

The code provided in the question works correctly, but there is an important note: 问题中提供的代码可以正常工作,但是有一个重要说明:

In C# you have to leave Application.Visible property with it's default value: 在C#中,您必须保留Application.Visible属性的默认值:

var application = new Application();
var document = application.Presentations.Open(fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, 
    WithWindow: MsoTriState.msoFalse);

If you explicitly set Application.Visible property to MsoTriState.msoFalse you will get "Hiding the application window is not allowed" error. 如果您将Application.Visible属性显式设置为MsoTriState.msoFalse ,则会出现“不允许隐藏应用程序窗口”错误。

I've tried this one, and it works:我试过这个,它有效:

Presentation p = app.Presentations.Open(presentation,0, 0, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM