怎么做淘宝网站步骤,wordpress后台很卡,淘宝网站建设目标是什么,嘉兴seo外包公司在做导出word文件功能时#xff0c;需要准备ftl模板#xff0c;设置一些通配符#xff0c;之后通过相关编码#xff0c;即可以实现业务数据渲染后导出word的功能。但是ftl文件一般我们看不太懂#xff0c;所以可视化创建和修改就非常合适。
1、安装office2016版本#x…在做导出word文件功能时需要准备ftl模板设置一些通配符之后通过相关编码即可以实现业务数据渲染后导出word的功能。但是ftl文件一般我们看不太懂所以可视化创建和修改就非常合适。
1、安装office2016版本wps2007office都不行 代码ftl文件 2、使用office2016word打开ftl文件 之后可以根据自己的需求去创建模板需要替换业务的场景使用${}定义通配符的方式。
3、示例代码 public void exportWord(HttpServletRequest request, HttpServletResponse response, String title) throws IOException {Map map new HashMapString, Object();map.put(deputeNo,11);//委托案号map.put(deputeUnitName, 22);//委托单位Template template configuration.getTemplate(aaa.ftl);File file null;InputStream fin null;ServletOutputStream out null;try {// 调用工具类的createDoc方法生成Word文档 String name word.doc;file new File(name);try {Writer writer new OutputStreamWriter(new FileOutputStream(file), utf-8);template.process(map, writer);writer.close();} catch (Exception ex) {ex.printStackTrace();throw new RuntimeException(ex);}fin new FileInputStream(file);response.setCharacterEncoding(utf-8);response.setContentType(application/msword);// 设置浏览器以下载的方式处理该文件名 String fileName title DateUtil.formatDate(new Date(), yyyy-MM-dd) .doc;response.setHeader(Content-Disposition, attachment;filename.concat(String.valueOf(URLEncoder.encode(fileName, UTF-8))));out response.getOutputStream();byte[] buffer new byte[512]; // 缓冲区 int bytesToRead -1;// 通过循环将读入的Word文件的内容输出到浏览器中 while ((bytesToRead fin.read(buffer)) ! -1) {out.write(buffer, 0, bytesToRead);}} finally {if (fin ! null) fin.close();if (out ! null) out.close();if (file ! null) file.delete(); // 删除临时文件}}
学海无涯苦作舟