zoukankan      html  css  js  c++  java
  • C# 《利用工具自动生成world的文档》

    第一步:项目引用  Aspose.Words.dll

    第二步:调用下列接口

      public void WorldSeve(Model.Work.wfPropertyDecoReform reformModel, int CreateById, Model.Person.pmAccount account)
            {
                #region 1.初始化模板变量
                string tmppath = System.Web.HttpContext.Current.Server.MapPath("违章整改模板.docx");//本地world 模板
                Document doc = new Document(tmppath); //载入模板
                DocumentBuilder builder = new DocumentBuilder(doc);
                #endregion
    
                #region 处理其他标签
                doc.Range.Bookmarks["name"].Text =CommonInfo.pmUserInfoName(CreateById);--  这里的 name  是你在world 模板上定义的标签名称
                doc.Range.Bookmarks["room"].Text = reformModel.RoomName.ToString();
                doc.Range.Bookmarks["reason"].Text = reformModel.Reason + "";
                doc.Range.Bookmarks["days"].Text = reformModel.ReformDates + "";
                doc.Range.Bookmarks["y1"].Text = Convert.ToDateTime(reformModel.PutDate).ToString("yyyy");
                doc.Range.Bookmarks["m1"].Text = Convert.ToDateTime(reformModel.PutDate).ToString("MM");
                doc.Range.Bookmarks["d1"].Text = Convert.ToDateTime(reformModel.PutDate).ToString("dd");
                doc.Range.Bookmarks["y2"].Text = Convert.ToDateTime(reformModel.CreateDate).ToString("yyyy");
                doc.Range.Bookmarks["m2"].Text = Convert.ToDateTime(reformModel.CreateDate).ToString("MM");
                doc.Range.Bookmarks["d2"].Text = Convert.ToDateTime(reformModel.CreateDate).ToString("dd");
                string fpath = System.Web.HttpContext.Current.Server.MapPath("doc");
                string fname = DateTime.Now.ToString("yyyyMMddHHmmss") + "违章管理.doc";
                if (!System.IO.Directory.Exists(fpath))
                    System.IO.Directory.CreateDirectory(fpath);
    
                if (System.IO.File.Exists(fpath + "/" + fname))
                    System.IO.File.Delete(fpath + "/" + fname);
    
                doc.Save(fpath + "/" + fname);
    
                //System.IO.FileInfo file = new System.IO.FileInfo(fpath + "/" + fname);
                //System.Web.HttpContext.Current.Response.Clear();
                //System.Web.HttpContext.Current.Response.Charset = "utf-8";
                //System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                //System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpContext.Current.Server.UrlEncode(fname));
                //System.Web.HttpContext.Current.Response.AddHeader("Conten-Length", file.Length.ToString());
                //System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                //System.Web.HttpContext.Current.Response.WriteFile(file.FullName);
                //System.Web.HttpContext.Current.Response.End();
    
                Model.Work.wfFiles fiel = new Model.Work.wfFiles();
                fiel.FileName = "违章整改模板.docx";
                fiel.FilePath = fname;
                fiel.BelongId = reformModel.Id;
                fiel.BelongTable = "wfPropertyDecoReform";
                fiel.Extend = ".doc";
                fiel.FileType = 102;
                fiel.State = (int)StateEnum.State.Enable;
                fiel.RoleId = Convert.ToInt32(CommonInfo.UserSysId(account.Id));
                fiel.CompanyId = Convert.ToInt32(CommonInfo.pmCompanyId(account.Id));
                fiel.CreateBy = account.AccountName;
                fiel.CreateById = account.Id;
                fiel.CreateDate = DateTime.Now;
                IBLL.Factory.wfFilesCreate().Add(fiel);
                #endregion
            }
  • 相关阅读:
    揭秘 HashMap 实现原理(Java 8)
    并发容器之写时拷贝的 List 和 Set
    Maven 整合 SSH 框架
    Hibernate框架学习之注解配置关系映射
    Hibernate框架学习之注解映射实体类
    单用户,多设备登录问题
    ios scrollview button 延时点击问题
    Android 的 AlarmManager 和 wakeLock联合使用
    ios bitcode 机制对 dsym 调试文件的影响
    信息类型的异步更新方法
  • 原文地址:https://www.cnblogs.com/shanshuiYiCheng/p/9908273.html
Copyright © 2011-2022 走看看