首页 > 其他 > 详细

操作word

时间:2014-10-25 17:07:55      阅读:258      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!