Qiang327 2014-12-23 06:59
浏览 2156

将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;
           }
       }           
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch