日期:2014-05-17  浏览次数:20881 次

在C#窗体上打开Word文档内容显示在richTextBox1控件上?100高分求教详细步骤
如题、要求:如题。。。我做的打开TXT文件没问题,但是打开Word文档就是乱码。只能打开系统写入的word文档,无语。求步骤。。。引用别忘了说。。。谢谢

------解决方案--------------------
2个我采用主要方法
1.word转为rtf格式后,richTextBox1.LoadFile(path)
2.生成一个word对象,复制其中内容,richTextBox1.Paste()
------解决方案--------------------
我这边正好做过,附上代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Office.Interop.Word;private void button1_Click(object sender, EventArgs e)
        {
                    //调用打开文件对话框获取要打开的文件WORD文件,RTF文件,文本文件路径名称
            OpenFileDialog opd = new OpenFileDialog();
            opd.InitialDirectory = "c:\\\\";
            opd.Filter = "Word文档(*.doc)
------解决方案--------------------
*.doc
------解决方案--------------------
文本文档(*.txt)
------解决方案--------------------
*.txt
------解决方案--------------------
RTF文档(*.rtf)
------解决方案--------------------
*.rtf
------解决方案--------------------
所有文档(*.*)
------解决方案--------------------
*.*";
            opd.FilterIndex = 1;

            if (opd.ShowDialog() == DialogResult.OK && opd.FileName.Length > 0)
            {
            //建立Word类的实例,缺点:不能正确读取表格,图片等等的显示
                ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationClass();
                Document doc = null;
            object missing = System.Reflection.Missing.Value;

            object FileName = opd.FileName;
            object readOnly = false;
            object isVisible = true;
            object index = 0;
            try
            {
             doc = app.Documents.Open(ref FileName, ref missing, ref readOnly,