码迷,mamicode.com
首页 > 其他好文 > 详细

操作word

时间:2014-10-25 17:08:09      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   for   sp   div   on   cti   bs   

using WordApplication = Microsoft.Office.Interop.Word.Application;
using Document = Microsoft.Office.Interop.Word.Document;
using Bookmark = Microsoft.Office.Interop.Word.Bookmark;        
  
public void WebPrint()
        {
            String modePath, tempPath;
            modePath = @"c:\model.doc";
            tempPath = @"c:\host.doc";
            WordApplication word = null;
            if (word == null)
            {
                try
                {
                    word = new WordApplication();
                }
                catch   
                {
  
                }
  
                object oMissing = System.Reflection.Missing.Value;
                object path1 = (object)modePath;
                object path2 = (object)tempPath;
                Document doc = null;
                doc = word.Documents.OpenOld(ref path1, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                foreach (Bookmark bm in doc.Bookmarks)
                {
                    switch (bm.Name)
                    {
                        case "host":
                            bm.Select();
                            bm.Range.Text="test";
                            break;
                    }
                }
                word.Visible = false;
  
                doc.SaveAs(ref path2, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                doc.PrintPreview();
                doc.Close(ref oMissing, ref oMissing, ref oMissing);
                word.Quit(ref oMissing, ref oMissing, ref oMissing);
                 
                word = null;
                  
            }

操作word

标签:io   os   ar   for   sp   div   on   cti   bs   

原文地址:http://www.cnblogs.com/kaiwanlin/p/4050221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!