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();



  • 相关阅读:
    畜栏预定【贪心+小根堆】
    电影【离散化】
    最佳牛栏(前缀和+二分)
    防晒【贪心 + 平衡树】
    货仓选址【中位数】证明
    24个不易混淆的数字和字母,常用于密码或密钥
    win8上的新功能,不知道win7有木有,刚偶然发现的
    通过C#类库绘制正态分布的统计图(通用)
    C#组播消息收发
    使用c#类库绘制柱状图
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1685756.html
Copyright © 2011-2022 走看看