poi-tl导出word文档
1、依赖:
2、参考博文:
https://blog.csdn.net/qq_31970227/article/details/113246795
https://www.cnblogs.com/pengdai/p/16537534.html#template%E6%A8%A1%E6%9D%BF
3、主要实现代码:
String filename = “导出文件的名字.docx”;
httpServletResponse response.setContentType("application/msword);
response.setcharacterEncoding("utf-8");
String name = URLEncoder.encode(filename,UTF-8);
response.setHeader(HttpHeaders.CONTENT_DISPISITION,"attachment; filename=\""+name+"\"; filename*=utf-8"+name);
InputStream fis = this.getClass().getClassLoader.getResourceAsStream(“templates/”+filename);
if(fis ==null){
throw exception
}
LoopRowTableRenderPolicy rowPolicy = new LoopRowTableRenderPolicy();
Configure config = Configure.builder().bind("fishPlist",rowPolicy) // 此处绑定数据到模版中的表格中去渲染,如果有多个列表时需加.bind("list",policy)继续绑定新列表即可
.build();
XWPFTemplatetemp = XWPFTemplatetemp.compile(fis,config).render(data); // data为数据实体
ByteArrayOutputStream out = new ByteArrayOutputStream();
temp.write(out);
if(fis != null){fis.close();}
InputStream docx = new ByteArrayInputStream(out.toByteArray());
hutool.IoUtil.copy(docx,response.getOutputStream());
out.close();
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章