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
            }
  • 相关阅读:
    Node 12 值得关注的新特性
    vue实现PC端调用摄像头拍照人脸录入、移动端调用手机前置摄像头人脸录入、及图片旋转矫正、压缩上传base64格式/文件格式
    解决Vuex刷新页面数据丢失问题 ---- vuex-persistedstate持久化数据
    博客搬迁到 gitHub + hexo 去了, 博客园以后比较少更新
    Jenkins结合shell脚本实现(gitLab/gitHub)前端项目自动打包部署服务器
    GET 和 POST 的区别 以及为什么 GET请求 比 POST请求 更快
    Git常用命令及使用,GitLab/GitHub初探,Git/Svn区别
    pc端结合canvas实现简单签名功能
    N的阶乘末尾0的个数和其二进制表示中最后位1的位置
    实现一个动态存储分配
  • 原文地址:https://www.cnblogs.com/shanshuiYiCheng/p/9908273.html
Copyright © 2011-2022 走看看