打开和修改 Word 文档 [英] Open and modify Word Document

查看:30
本文介绍了打开和修改 Word 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Microsoft.Office.Interop.Word"打开保存在我的服务器中的 word 文件.这是我的代码:

I want to open a word file saved in my server using "Microsoft.Office.Interop.Word". This is my code:

    object missing = System.Reflection.Missing.Value;
    object readOnly = false;
    object isVisible = true;
    object fileName = "http://localhost:52099/modelloBusta/prova.dotx";
    Microsoft.Office.Interop.Word.ApplicationClass applicationWord = new Microsoft.Office.Interop.Word.ApplicationClass();
    Microsoft.Office.Interop.Word.Document modelloBusta = new  Microsoft.Office.Interop.Word.Document();

    try
    {

        modelloBusta = applicationWord.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref  missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible,ref missing, ref missing, ref missing, ref missing);
        modelloBusta.Activate();



    }
    catch (COMException eccezione){
        Console.Write(eccezione);
        modelloBusta.Application.Quit(ref missing, ref missing, ref missing);

    }

在 windows 任务管理器中,进程存在,但word 文档"没有出现(应用程序没有启动).问题是什么?提前致谢.

In the windows task manager the process is present, but the "word document" doesn't appear (the application does not start). What is the problem? Thanks in advance.

推荐答案

您需要确保在像这样自动化 Word 时,Word 应用程序窗口实际上是可见的:

You need to make sure that the Word application window actually is made visible when automating Word like that:

var applicationWord = new Microsoft.Office.Interop.Word.Application();
applicationWord.Visible = true;

这篇关于打开和修改 Word 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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