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

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

nankui
2022-03-17 / 0 评论 / 882 阅读 / 正在检测是否收录...
  • 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();
    }
}

浏览器
360截图17401211525937.png
本地
360截图16270831729394.png
模板
word.zip

0

评论 (0)

取消