- 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
评论 (0)