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();
                }
            }
        }

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM