zoukankan      html  css  js  c++  java
  • 操作word

    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;
                      
                }
  • 相关阅读:
    RFM模型
    mysql日期函数(时间函数)
    数据库探索
    anaconhda安装步骤
    mysql安装和环境配置
    mysql时间条件查询
    mysql自连接
    mysql查询注意事项(查询优化)
    mysql常见的保留字和反引号使用
    多表联合查询注意事项(索引)
  • 原文地址:https://www.cnblogs.com/kaiwanlin/p/4050221.html
Copyright © 2011-2022 走看看