如何隐藏Word和excel在C#中显示在屏幕上 [英] How do I hide word and excel from displaying on screen in C#

查看:102
本文介绍了如何隐藏Word和excel在C#中显示在屏幕上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



当我处理一些文件时,我试图隐藏Word和Excel。

我知道它甚至不能在任务栏上显示但是作为一个进程隐藏但是我似乎无法使其工作。

我也不确定创建excel表或图表是否会导致此问题还有。



任何建议都表示赞赏。

谢谢。



我尝试过:



这是我目前拥有的代码片段。

Hi All,

I am trying to hide Word and Excel from displaying when I am processing some documents.
I know it is capable of not even being displayed on the taskbar but hidden as a process but I can't seem to get that to work.
I am also not sure if creating excel tables or charts is causing this problem as well.

Any advice is appreciated.
Thank you.

What I have tried:

Here is a code fragment that I currently have.

object missing = System.Reflection.Missing.Value;
            object readOnly = true;
            object addToRecentFiles = false;
            object visible = false;

            object filename = Path.Combine(Directory.GetCurrentDirectory(), "Lorem ipsum dolor sit amet.docx");

            Word.Application word = null;
            word = new Word.Application();
            word.Visible = false;

            Word.Documents documents = word.Documents;
            Word.Document doc = documents.Open(ref filename, ref missing, ref readOnly, ref addToRecentFiles, ref missing, ref missing, true, ref missing, ref missing, ref missing, ref missing, ref visible, ref missing, ref missing, ref missing, ref missing);
            doc.Activate();

推荐答案

引用:

我知道它甚至不能显示在任务栏上但是作为一个进程被隐藏但是我似乎无法让它工作。

我也不确定是否创建excel表或图表也会导致这个问题。

I know it is capable of not even being displayed on the taskbar but hidden as a process but I can't seem to get that to work.
I am also not sure if creating excel tables or charts is causing this problem as well.





对不起,但你错了!

你做了不要通过说似乎无法使其工作来指明您的意思,并且您没有提供有关错误消息的信息。然而......

你无法让它工作的原因很明显......问题出在这里:



Sorry, but you're wrong!
You did not specify what you mean by saying "can't seem to get that to work" and you didn't provide information about error message. Nevertheless...
The reason you can't get it to work is quite obvious... The problem is laying in here:

doc.Activate();





当托管应用程序不可见时,您无法激活文档(将焦点移到它上面)。删除使用方法的每一行:激活()选择(),一切都应该开始工作。



You can't activate a document (move focus to it) when hosting application is invisible. Remove every line which uses methods: Activate() and Select() and everything should start working.


尝试这种方式,这对我有用



try this way , this works for me

// Create an Application object

Microsoft.Office.Interop.Word.ApplicationClass ac = new Microsoft.Office.Interop.Word.ApplicationClass();

Microsoft.Office.Interop.Word.Application app = ac.Application;

app.DisplayAlerts = Microsoft.Office.Interop.Word.

WdAlertLevel.wdAlertsNone;

object filename = strFileName;

object missingValue = Type.Missing;

app.Visible = true;

Microsoft.Office.Interop.Word.

Document document = app.Documents.OpenOld(ref filename,ref missingValue, ref missingValue,ref missingValue, ref missingValue, ref missingValue,ref missingValue, ref missingValue, ref missingValue, ref missingValue);

app.Activate();

}


这篇关于如何隐藏Word和excel在C#中显示在屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆