日期:2014-05-17 浏览次数:20914 次
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,