jeecg-boot word导出 导出下载 模板导出


  • jeecd-boot 导出word JEECG Word模板导出教程

功能目标:读取word模板,解析数据导出word,对数据赋值
代码:

pom.xml

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <nonFilteredFileExtensions>
                    <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                    <nonFilteredFileExtension>eot</nonFilteredFileExtension>
                    <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                    <nonFilteredFileExtension>docx</nonFilteredFileExtension>
                </nonFilteredFileExtensions>
            </configuration>
        </plugin>


  public void simpleWordExport(HttpServletResponse response) {
    Map<String, Object> map = new HashMap<>();
    map.put("title", "标题");
    map.put("content", "内容");
    map.put("year", 1);
    map.put("month", 2);
    map.put("name","名称");
    map.put("day", "10");
    try {

      // 导出下载 
      //templates/word.docx   模板路径
        XWPFDocument doc = WordExportUtil.exportWord07(
                "templates/word.docx", map);
        response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document;chartset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode("1", "UTF8") + ".docx");
        ServletOutputStream out=response.getOutputStream();
        doc.write(out);
        out.flush();
        out.close();
        // 导出本地
        // FileOutputStream fos = new FileOutputStream("D:/360/simple.docx");
       // doc.write(fos);
       // fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

浏览器

本地

模板
word.zip

声明:雨墨博客-分享宝塔面板使用,VPS教程,域名教程以及互联网技巧的个人博客|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - jeecg-boot word导出 导出下载 模板导出


Carpe Diem and Do what I like