导出doc

  public static void crateFile(HttpServletResponse response, SiInterview siInterview){
        XWPFTemplate template = null;
        try {
            template = XWPFTemplate
                    .compile(new ClassPathResource("/templates/约谈通知书.docx").getFile().getPath())
                    .render(
                    new HashMap<String, Object>(){{
                        put("intervieweeUnit", siInterview.getIntervieweeUnitName());
                        put("interviewee", siInterview.getIntervieweeName());
                        put("interviewPlace", siInterview.getInterviewPlace());
                        if (siInterview.getInterviewTime()!=null){
                            put("interviewTime", DateUtils.parseDateToStr("yyyy年MM月dd日 HH时mm分",siInterview.getInterviewTime()));
                        }
                        put("interviewMatter", siInterview.getInterviewMatter());
                    }});
            ServletOutputStream outputStream = response.getOutputStream();
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition","attachment;filename=".concat(URLEncoder.encode("约谈通知书.docx", "UTF-8")));
            BufferedOutputStream bos = new BufferedOutputStream(outputStream);
            template.write(bos);
            bos.flush();
            outputStream.flush();
            PoitlIOUtils.closeQuietlyMulti(template, bos, outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

导出doc

    <dependency>
            <groupId>com.deepoove</groupId>
            <artifactId>poi-tl</artifactId>
            <version>1.9.1</version>
        </dependency>

 

上一篇:将DataGridview的内容保存到Excel


下一篇:js中filter方法和map方法的作用及区别