springboot导出Excel文件给浏览器下载

Java代码:

复制代码
 1 BufferedOutputStream fos = null;
 2 try {
 3     response.setContentType("application/x-msdownload");
 4     response.setCharacterEncoding("UTF-8");
 5     response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("mock", "UTF-8") + ".xlsx");
 6     fos = new BufferedOutputStream(response.getOutputStream());
 7     xssfWorkbook.write(fos);
 8 } catch (Exception e) {
 9     log.error("excel生成报错:{}", e);
10 } finally {
11     if (fos != null) {
12         try {
13             fos.close();
14         } catch (IOException e) {
15             log.error("流对象关闭失败");
16         }
17     }
18 }
复制代码

 

posted @   没有你哪有我  阅读(406)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
历史上的今天:
2021-03-23 如何使用IDEA来搭建第一个SpringBoot项目
点击右上角即可分享
微信分享提示