陈宝刚---享受生活,追逐梦想!
理想是心中的火焰,有追求的人才是幸福的人!

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



posted on 2010-03-14 21:49  追梦人RUBY  阅读(878)  评论(0编辑  收藏  举报