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;
                      
                }
  • 相关阅读:
    ros学习之消息和服务
    linux软件安装
    ros使用QT插件开发
    使用客户端对象模型读取SharePoint列表数据
    使用服务器端对象模型,编写程序管理SharePoint列表
    Visual Studio创建简单的Event Receiver
    在SharePoint中使用LINQ
    使用Visual Stuidio 2010 创建网站列
    使用Visual Studio 创建新的Web Part项目
    在SharePoint页面嵌入简单的Silverlight程序
  • 原文地址:https://www.cnblogs.com/kaiwanlin/p/4050221.html
Copyright © 2011-2022 走看看