• 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
            }
  • 相关阅读:
    性能监控(5)–JAVA下的jstat命令
    内存分析工具-MAT(Memory Analyzer Tool)
    性能监控(4)–linux下的pidstat命令
    性能监控(3)–linux下的iostat命令
    性能监控(2)–linux下的vmstat命令
    性能监控(1)--linux下的top命令
    了解java虚拟机—在TALB上分配对象(10)
    了解java虚拟机—G1回收器(9)
    js 长按鼠标左键实现溢出内容左右滚动滚动
    html标签设置contenteditable时,去除粘贴文本自带样式
  • 原文地址:https://www.cnblogs.com/shanshuiYiCheng/p/9908273.html
Copyright © 2020-2023  润新知