当前位置: 首页 > news >正文

柳州正规网站建设加盟网络互动公司排名

柳州正规网站建设加盟,网络互动公司排名,注册的网站,郑州网站建设网站8、jeecg 笔记之 自定义word 模板导出#xff08;一#xff09; 1、前言 jeecg 中已经自带 word 的导出导出功能#xff0c;其所使用的也是 easypoi#xff0c;尽管所导出的 word 能满足大部分需求#xff0c; 但总是有需要用到自定义 word导出模板#xff0c;下文所用到… 8、jeecg 笔记之 自定义word 模板导出一 1、前言 jeecg 中已经自带 word 的导出导出功能其所使用的也是 easypoi尽管所导出的 word 能满足大部分需求 但总是有需要用到自定义 word导出模板下文所用到的皆是 easypoi 提供的为方便下次翻阅故记之。   2、代码部分 2.1、controller RequestMapping(/ftl2word) public void velocity2word(JeecgDemoExcelEntity jeecgDemoExcel, HttpServletRequest request,HttpServletResponse response) throws IOException {try {jeecgDemoExcel this.jeecgDemoExcelService.getEntity(JeecgDemoExcelEntity.class, jeecgDemoExcel.getId());ListMapString, Object departs this.systemService.findForJdbc(select id,departname from t_s_depart);String docFileName word-模板导出测试.doc;MapString, Object rootMap new HashMapString, Object();rootMap.put(info, jeecgDemoExcel);rootMap.put(departs, departs);// FreemarkerUtil.createFile(exportMyExcel.xls,// docFileName,rootMap, request, response,// FreemarkerUtil.EXCEL_FILE);FreemarkerUtil.createFile(ftl2doc.ftl, docFileName, rootMap, request, response, FreemarkerUtil.WORD_FILE);} catch (Exception e) {e.printStackTrace();} }   2.2、entity 实体就不扔出来了详细说一下这个地方 jeecgDemoExcel this.jeecgDemoExcelService.getEntity(JeecgDemoExcelEntity.class, jeecgDemoExcel.getId()); ListMapString, Object departs this.systemService.findForJdbc(select id,departname from t_s_depart); String docFileName word-模板导出测试.doc; MapString, Object rootMap new HashMapString, Object(); rootMap.put(info, jeecgDemoExcel); rootMap.put(departs, departs); jeecgDemoExcel  为 List实体departs 为 ListMapString, Object怎么用ftl 语法了解一下 2.3、工具类 FreemarkerUtil  public class FreemarkerUtil {private static final Object LOCK new Object();/*** word文件*/public static final int WORD_FILE 1;/*** excel文件*/public static final int EXCEL_FILE 2;private static Configuration cfg;private static FreemarkerUtil ftl ;private FreemarkerUtil(String templateFolder) throws IOException {cfg new Configuration();cfg.setDirectoryForTemplateLoading(new File(templateFolder));cfg.setObjectWrapper(new DefaultObjectWrapper());}private static void check(HttpServletRequest request) {if (ftl null) {synchronized (LOCK) {try {ftl new FreemarkerUtil(request.getServletContext().getRealPath(/)export/template);} catch (IOException e) {e.printStackTrace();}}}}/*** 创建 word 文档* 必须先设置response导出配置然后解析模版否则会出问题* throws IOException */public static void createFile(String templateName,String docFileName, MapString,Object rootMap,HttpServletRequest request, HttpServletResponse response,int fileType) throws IOException {// response.resetBuffer();//设置导出response.addHeader(Cache-Control,no-cache);response.setCharacterEncoding(UTF-8);if( WORD_FILE fileType){response.setContentType(application/vnd.ms-word;charsetUTF-8);}else if(EXCEL_FILE fileType){response.setContentType(application/octet-stream;charsetUTF-8);}else{response.setContentType(application/octet-stream);}String ua request.getHeader(user-agent);ua ua null ? null : ua.toLowerCase();if(ua ! null (ua.indexOf(firefox) 0 || ua.indexOf(safari)0)){try {docFileName new String(docFileName.getBytes(),ISO8859-1);response.addHeader(Content-Disposition,attachment;filename docFileName);} catch (Exception e) {}}else{try {docFileName URLEncoder.encode(docFileName, utf-8);response.addHeader(Content-Disposition,attachment;filename docFileName);} catch (Exception e) {}}check(request);//解析模版Template temp cfg.getTemplate(templateName, UTF-8);PrintWriter write response.getWriter();try {temp.process(rootMap, write);} catch (TemplateException e) {e.printStackTrace();}finally {if(write ! null){write.flush();write.close();}}} }   2.4、ftl 模板 https://files.cnblogs.com/files/niceyoo/ftl2doc.rar 至于ftl 如何生成以及如何写可自定查询后面也会单独文章补充。    博客地址http://www.cnblogs.com/niceyoo   posted 2018-12-17 13:33 niceyoo 阅读(...) 评论(...) 编辑 收藏
http://www.pierceye.com/news/176760/

相关文章:

  • 58同城长沙回收网站建设长春seo推广
  • 景区网站建设的意义女生学计算机应用技术可以做什么
  • 做律师网站的公司天津公司网站制作
  • 上海建设摩托车官方网站招聘网站数建设
  • 自己制作一个网站需要什么软件安吉网站制作
  • 如何设计服装网站首页网站建设比较好的公司
  • 微信网站的链接标志图片如何做公众号如何创建
  • 建站公司建的网站能改动吗怎样设置默认网站
  • 高并发电商网站开发辽宁省朝阳市做网站
  • 公司做网站有用吗合肥企业快速建站
  • 因脉网站建设公司怎么呀韩国网站开发建设技术特点
  • 网站备案 个人 单位安徽网站建设推广
  • 黔江网站制作网站招标建设
  • 网站注册公司目前最好的引流方法
  • 小米wifi设置网址入口网站通信工程建设网站
  • 深圳专业网站建在线做插画的网站
  • 站长之家网站查询怎么样创建自己的小程序
  • 站酷海报设计图片网站备份怎么做
  • 做网站挣钱么云市场 wordpress
  • 网站域名管理规范seo专员是什么
  • 网站制作+资讯网站特色栏目重要性
  • 网站qq 微信分享怎么做的随州市住房和城乡建设部网站
  • 资源网站建设多少钱手机网站页面文字做多大
  • 烟台专业做网站宜昌教育云网站建设
  • 慕课联盟网站开发实战wordpress怎样修改域名
  • 什么电脑做网站前段用旅游网站建设的利益
  • 做 暧视频在线观看网站花都网站建设设计
  • 黄石企业网站设计服务外包有哪些
  • 团队合作网站网站制作的报价大约是多少
  • 网站在线留言系统能挣钱的平台 正规的