日期:2014-05-18  浏览次数:20748 次

想点一个按钮,打开一个Word文档。
比如想在C#程序中点个按钮,利用Word程序打开c:\aa.doc 结人看。
用哪个函数,怎么做?
先谢谢大家了。


------解决方案--------------------
System.Diagnostics.Process.Start(FileName);
------解决方案--------------------
System.Diagnostics.Process.Start就够了,会调用默认的关联程序打开的,doc应该默认就是word
------解决方案--------------------
下面是控件

需要安裝office



不需要安裝office
------解决方案--------------------
如果只需要打开,上面的操作就够了。如果需要操作WORD文档,可以调用word的api
C# code

using Word = Microsoft.Office.Interop.Word
public class word
{
    Word.Application app;    //Word应用程序变量
     Word.Document doc;       //Word文档变量
     object missing = Type.Missing;

     public WordOper()
        {
            app = new Word.Application();
            app.Visible = true;
        }

    public void Open()
        {
            doc = app.Documents.Open(ref _fileName,
                ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing);
        }
}

------解决方案--------------------
System.Diagnostics.Process.Start(FileName);足够了
------解决方案--------------------

用webbrowser也能打开

给它的URI属性赋 new Uri(@"X:\XX.doc");
------解决方案--------------------
System.Diagnostics.Process.Start会调用默认的关联程序打开
------解决方案--------------------
打开Word:
Word.Application wapp = new Microsoft.Office.Interop.Word.Application();
wapp.Visible = true;
wapp = null;

打开一个现有的Word文档:
Word.Application wapp = new Microsoft.Office.Interop.Word.Application();
wapp.Visible = true;
object filename = "E:\\Task.doc";
object isread = false;
object isvisible = true;
object miss = System.Reflection.Missing.Value;

wapp.Documents.Open(ref filename, ref miss, ref isread, ref miss, ref miss, ref miss, ref miss, ref miss,

ref miss, ref miss, ref miss, ref isvisible, ref miss, ref miss, ref miss, ref miss);

wapp = null;

打开一个新文档:
Word.Application wapp = new Microsoft.Office.Interop.Word.Application();
Word.Document adoc = new Microsoft.Office.Interop.Word.Document();
wapp.Visible = true;
object miss = System.Reflection.Missing.Value;
adoc = wapp.Documents.Add(ref miss, ref miss, ref miss, ref miss);

wapp = null;
添加using System.Reflection; using Microsoft.Office.Interop.Word; 引用
------解决方案--------------------
System.Diagnostics.Process.Start(FileName);
------解决方案--------------------
System.Diagnostics.Process.Start(@"c:\aa.doc");

这样就可以了。