其他分享
首页 > 其他分享> > 导出doc

导出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();
        }
    }

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

 

标签:outputStream,doc,siInterview,bos,导出,template,put,response
来源: https://www.cnblogs.com/-mzh/p/15901013.html