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

发布于 2024-11-06 10:38:32 字数 866 浏览 3 评论 0原文

我想通过互操作打开一个word文档,并且word必须在该过程中可见。它看起来相当简单,因为在word文档的打开函数中有一个名为“visible”的参数。但是word在后台。什么我失踪了吗?

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

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

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

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

发布评论

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

评论(1

ζ澈沫 2024-11-13 10:38:33

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

word.Visible = true;

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