通过互操作打开文档时如何使单词可见? [英] How can I make word visible when opening a document through interop?

查看:71
本文介绍了通过互操作打开文档时如何使单词可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过互操作打开单词文档,并且单词在过程中必须可见.它看起来很简单,因为在单词文档的open函数中有一个名为"visible"的参数.背景.我想念什么?

I want to open a word document through interop and word must be visible in the process.It looks to be fairly straight forward because there is a parameter called "visible in the open function on a word document. But word is in the background. What am I missing?

static void Main(string[] args)
{
    Microsoft.Office.Interop.Word.Application word = null;
    word = new Microsoft.Office.Interop.Word.Application();

    object inputFile = "c:\\test.docx";
    object confirmConversions = false;
    object readOnly = true;
    object visible = true;
    object missing = Type.Missing;

    // Open the document...
    Microsoft.Office.Interop.Word.Document doc = null;
    doc = word.Documents.Open(
        ref inputFile, ref confirmConversions, ref readOnly, ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref visible,
        ref missing, ref missing, ref missing, ref missing);
    doc.Activate();

    Console.ReadKey();
}

推荐答案

嗯.显然,应用程序和文档都必须可见.因此,解决方案是在doc.Activate()之前添加行:

Hmm. Apparantly both the application and the document has to be visible. So the solution is to add the line (before doc.Activate() ):

word.Visible = true;

这篇关于通过互操作打开文档时如何使单词可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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