zoukankan      html  css  js  c++  java
  • C# 通过word模板动态生成Word

                        object oMissing = System.Reflection.Missing.Value;
                        Word._Application oWord = new Word.Application();
                        oWord.Visible = false;
                        object oTemplate = HttpContext.Current.Server.MapPath("~/files/userword/Temp/LendMoneyDemo.dot");
                        Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
                        object[] oBookMark = new object[10];
                        oBookMark[0] = "username";
                        oBookMark[1] = "useridcard";
                        oBookMark[2] = "totalmoney";
                        oBookMark[3] = "totalday";
                        oBookMark[4] = "startday";
                        oBookMark[5] = "endday";
                        oBookMark[6] = "fuwufee";
                        oBookMark[7] = "httongname";
                        oBookMark[8] = "httongdatea";
                        oBookMark[9] = "hetongdateb";
    
                       
    
                        oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = UserInfo.realName;
                        oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = UserInfo.idCard;
                        oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = total.ToString(); ;
                        oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = totalday.ToString();
                        oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = DateTime.Now.ToString("yyyy年MM月dd日");
                        oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = enddate;
                        oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = (total / 10).ToString();
                        oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = UserInfo.realName;
                        oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = DateTime.Now.ToString("yyyy年MM月dd日");
                        oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text = DateTime.Now.ToString("yyyy年MM月dd日");
    
                        object filename = HttpContext.Current.Server.MapPath("~/files/userword/Word/" + tokenId + "_LendMoney.docx");
    
                        oDoc.SaveAs(ref filename, 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);
    
                        oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
    
                        oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
  • 相关阅读:
    tomcat 虚拟目录
    linux 基本常用命令
    linux shell
    分布式锁
    多线程 ThreadLocal
    Java并发包中Lock的实现原理
    spring 异常处理
    spring Cache /Redis 缓存 + Spring 的集成示例
    spring 事务传播行为
    Vue.nextTick浅析
  • 原文地址:https://www.cnblogs.com/myshowtime/p/6281735.html
Copyright © 2011-2022 走看看