zoukankan      html  css  js  c++  java
  • c#操作word 在指定书签插入文字或者图片

    using Word = Microsoft.Office.Interop.Word;

    object Nothing = System.Reflection.Missing.Value;
             object format = Word.WdSaveFormat.wdFormatDocument;
             Word.Application wordApp = new Word.ApplicationClass();
             //打开网页选择内容
             object srcFileName = @"c:\new1.doc"; //里面有图片
              Word.Document wordDoc2 = wordApp.Documents.Open(ref srcFileName, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                try
    {
                 object bookmarkName = "jlr";
                 //Word.Range rng = wordDoc2.Bookmarks.get_Item(ref bookmarkName).Range;
                 //rng.Text = "newText";
                 //object range = rng;
                 //wordDoc2.Bookmarks.Add("jlr", ref range);
                 wordDoc2.Bookmarks.get_Item(ref bookmarkName).Select();
                 wordApp.Selection.InlineShapes.AddPicture("c:\\1.jpg", ref Nothing, ref Nothing, ref Nothing);
                 wordDoc2.Save();

          

             }
             catch { }
             finally
             {
                 //关闭网页wordDoc2
                 wordDoc2.Close(ref Nothing, ref Nothing, ref Nothing);
                 if (wordDoc2 != null)
                 {
                     System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc2);
                     wordDoc2 = null;
                 }
                 //关闭wordApp
                 wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
                 if (wordApp != null)
                 {
                     System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
                     wordApp = null;
                 }
             }
             GC.Collect();



  • 相关阅读:
    WordPress后台添加友情链接管理功能
    WordPress评论时一键填入昵称、邮箱和网址
    七牛云存储更新缓存图片的方法
    WordPress文章中插入qq表情
    WordPress文章页添加展开/收缩功能
    WordPress添加显示和隐藏侧边栏按钮开关
    Defraggler磁盘碎片整理工具,让你的电脑读写速度更快
    如何彻底关闭系统还原功能和删除系统还原点
    WordPress博客彻底关闭图片缩略图功能的方法
    WP Super Cache+七牛云配置CDN加速,让你的网站秒开
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1685756.html
Copyright © 2011-2022 走看看