zoukankan      html  css  js  c++  java
  • C# 操作word 模板 值 替换

    1.引用 aspose.words   dll

    2.word 使用doc  

    3.给word 模板中添加要替换位置的 书签

    1.引用 aspose.words   dll
    2.word 使用doc  
    
    3.给word 模板中添加要替换位置的 书签
    
    
    
     string templatePath = Server.MapPath("~" + path);//文档模板物理路径
    
                Document doc = new Document(templatePath);
                try
                {
                    Hashtable tables = new Hashtable();
                    tables.Add("协议编号", ""+agreeNum+"");
                    tables.Add("基金管理人", orgName);
                    tables.Add("基金管理人住所", orgFundCompanyAddr);
                    tables.Add("法定代表人", orgCorporationName);
                    tables.Add("基金投资者", investorName);
                    tables.Add("基金投资者住所", InvestorAddress);
                    tables.Add("投资者身份证号", investorIdCard);
                    tables.Add("投资者性别", InvestorSex);
                    tables.Add("投资者联系方式", InvestorTel);
                    tables.Add("投资者年龄", InvestorAge);
                    
    
                    tables.Add("基金合同编号", ""+htNum+"");
                    tables.Add("基金合同编号2",  htNum );
                    tables.Add("基金合同名称", ""+fundName+"私募基金合同》");
                    tables.Add("金额大写", Common.Utils.MoneyToUpper((Utils.StrToDecimal(loanAmount, 0)).ToString()).Replace("圆整",""));//不带单位只读数字
    
                    tables.Add("金额小写", (String.Format("{0:N}", Utils.StrToDecimal(loanAmount, 0) * 10000)));
                    tables.Add("金额小写不乘一万", (String.Format("{0:N}", Utils.StrToDecimal(loanAmount, 0))));
                    tables.Add("付款日期", beginTime);
                    tables.Add("付款日期2", beginTime2);
                    tables.Add("收益开始日期", beginTime);
                    tables.Add("封闭开始日期", beginTime);
                    tables.Add("封闭结束日期", endTime);
                    tables.Add("封闭月数", totalMonth);
                    tables.Add("开户行", fundActBankName);
                    tables.Add("银行卡号", fundActBankNum);
                    tables.Add("基金账户名称", fundActName);
                    tables.Add("通知日期", beginTime);
                    tables.Add("基金名称", fundName + "私募投资");
                    tables.Add("委托人银行卡号", agentBankNum);
                    tables.Add("委托人开户行", agentBankName);
                    tables.Add("委托人账户名称", agentName);
    
                    GetHTFile(doc, tables);
                    string downname = investorName + "-" + name;
                    doc.Save(downname, SaveFormat.Doc, SaveType.OpenInWord, Page.Response);
                }
                catch(Exception ex)
                {
                   
                }
      
    public static void GetHTFile(Document doc, Hashtable table)
            {
                BookmarkCollection bookmarks = doc.Range.Bookmarks;
                foreach(Bookmark mark in bookmarks)
                {
                    if(table.ContainsKey(mark.Name))
                    {
                        mark.Text = table[mark.Name].ToString();
                    }
                }
            }

      

  • 相关阅读:
    hibernate_0100_HelloWorld
    MYSQL子查询的五种形式
    JSF是什么?它与Struts是什么关系?
    nop指令的作用
    htmlparser实现从网页上抓取数据(收集)
    The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the
    FCKeditor 在JSP上的完全安装
    Java遍历文件夹的2种方法
    充电电池和充电时间说明
    吃知了有什么好处
  • 原文地址:https://www.cnblogs.com/kaikaichao/p/10270175.html
Copyright © 2011-2022 走看看