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;
             }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值