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

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

问题描述

我要打开保存在使用的Microsoft.Office.Interop.Word我的服务器一个word文件。
这是我的code:

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任务管理器的进程present,但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天全站免登陆