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;
                      
                }
  • 相关阅读:
    vivado 连接不上板子 There is no current hw_target
    excel 方框打钩
    2019新个税如何计算
    printf("loops %u / %u%c[K ", loops + 1, opts->loops, 27); printf("%cM", 27);
    HttpUtil
    Spring注入bean和aop的注意事项
    获取所有bean的名字
    不可见类有抽象父类,spring配置子类bean,注入父类,aop就可以切父类的方法
    实例/静态工厂方法得到bean
    注入抽象类的子类
  • 原文地址:https://www.cnblogs.com/kaiwanlin/p/4050221.html
Copyright © 2011-2022 走看看