Qiang327
Qiang327
2014-12-23 06:59

将word文档中的内容导入到richtextbox中,包括文字和一些图片

       现在需要将word文档中的内容导入到richtextbox中,  我自己写的代码总是不成功,多张图片只显示一张,其余显示不出来,这是怎么回事?
        代码:
         private void bt_open_Click_1(object sender, RoutedEventArgs e)
    {
        //if (tb_text.Text=="")
        //{
        //    MessageBox.Show("请输入路径!");
        //    return;  
        //}

        Microsoft.Office.Interop.Word.ApplicationClass app = new Microsoft.Office.Interop.Word.ApplicationClass();
        Microsoft.Office.Interop.Word.Document doc = null;
        Microsoft.Office.Interop.Word.Application obj = null;
       object missing = System.Reflection.Missing.Value;
       //object File = "C:\\Users\\shuai\\Desktop\\test.docx";
       object File = "D:\\picture\\test.doc";
       object readOnly = false;
       object isVisible = true;
       try
       {

           doc = app.Documents.Open(ref File, ref missing, ref missing, 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);

           doc.ActiveWindow.Selection.WholeStory();//全选word文档中的数据
           doc.ActiveWindow.Selection.Copy();//复制数据到剪切板
           rtb_text.Paste();//richTextBox粘贴数据
           doc.Close();
       }
       catch (Exception Ex)
       {
           System.Windows.MessageBox.Show(Ex.ToString());
           Console.Write("打开失败\n");
       }
       finally
       {
           if (doc != null)
           {
               doc.Close(ref missing, ref missing, ref missing);
               doc = null;
           }
           if (app != null)
           {
               app.Quit(ref missing, ref missing, ref missing);
               app = null;
           }
       }           
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

为你推荐