把图片在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;
作者:Ants_double
出处:https://www.cnblogs.com/ants_double/
本文版权归作者和博客园所有,欢迎转载。转载请在留言板处留言给我,且在文章标明原文链接,谢谢!
如果您觉得本篇博文对您有所收获,觉得我还算用心,请点击右下角的 [大拇指],谢谢!