在项目引用里添加上对Microsoft Word 11.0 object library的引用

时间:2022-08-16 17:10:46

private void button1_Click(object sender, System.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类的实例,缺点:不能正确读取表格,图片等等的显示

Word.ApplicationClass app = new Word.ApplicationClass();

Word.Document doc = null;

object missing = System.Reflection.Missing.Value;

object FileName = opd.FileName;

object read}

}