博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

把图片在word中显示

如下:

  //放入word中

            #region word

            ThreadPool.QueueUserWorkItem(//使用线程池
              (P_temp) =>//使用lambda表达式
              {
                  G_wa = new Word.Application();//创建Word应用程序对象
                  Word.Document P_wd = G_wa.Documents.Add(//建立新文档
                      ref G_missing, ref G_missing, ref G_missing, ref G_missing);
                  Word.Range P_Range = P_wd.Paragraphs[1].Range;//得到段落范围
                  object P_Ranges = P_Range;//创建ojbect对象
                  P_wd.InlineShapes.AddPicture(//向文档中插入图片
                      strChart3, ref G_missing, ref G_missing, ref P_Ranges);
                  P_wd.InlineShapes.AddPicture(//向文档中插入图片
                    strChart2, ref G_missing, ref G_missing, ref P_Ranges);
                  P_wd.InlineShapes.AddPicture(//向文档中插入图片
                    strChart1, ref G_missing, ref G_missing, ref P_Ranges);
                  G_str_path = string.Format(//计算文件保存路径
                      @"{0}\{1}", strPath,
                      DateTime.Now.ToString("yyyy年M月d日h时s分m秒fff毫秒") + ".doc");
                  P_wd.SaveAs(//保存Word文件
                      ref G_str_path,
                      ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                      ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                      ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                      ref G_missing, ref G_missing, ref G_missing);
                  ((Word._Application)G_wa.Application).Quit(//退出应用程序
                      ref G_missing, ref G_missing, ref G_missing);
                  //  this.Dispatcher.Invoke(//开始执行窗体线程
                  //  (MethodInvoker)(() =>//使用lambda表达式
                  //   {
                  // btn_Display.Enabled = true;//启用显示按钮
                  System.Windows.MessageBox.Show("成功创建Word文档!", "提示!");
                  //  }));
              });
            #endregion

  

   private Word.Application G_wa;//定义Word应用程序字段
        private object G_missing = //定义missing字段并赋值
            System.Reflection.Missing.Value;
        private object G_str_path;//定义文件保存路径字段
        private OpenFileDialog G_OpenFileDialog;//定义打开文件对话框字段
        private FolderBrowserDialog G_FolderBrowserDialog;//定义文件夹浏览对话框字段

  

using System.Diagnostics;
using System.Xml.Linq;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using System.IO;

  

posted @ 2016-04-06 15:27  ants_double  阅读(280)  评论(0编辑  收藏  举报