通过互操作打开文档时,如何使单词可见?

时间:2011-05-11 12:53:02

标签: c# interop ms-word

我想通过互操作打开一个word文档,并且word必须在进程中可见。它看起来相当直接,因为在word文档的open函数中有一个名为“visible”的参数。但是单词在我错过了什么?

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

1 个答案:

答案 0 :(得分:6)

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

word.Visible = true;