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;
                      
                }
  • 相关阅读:
    完全背包详解
    0-1背包详解
    优先队列 + 模拟
    循环节 + 矩阵快速幂
    并查集 + 路径压缩(经典) UVALive 3027 Corporative Network
    dp
    动态规划分类(完整版)
    (二)Spring框架之JDBC的基本使用(p6spy插件的使用)
    (一)Spring框架基础
    (十六)客户端验证与struts2中的服务器端验证
  • 原文地址:https://www.cnblogs.com/kaiwanlin/p/4050221.html
Copyright © 2011-2022 走看看