1、将excel文件放项目resources目录下

2、打包的时候排除指定后缀文件,否则打包时会出现文件损坏的情况
 <configuration>
<encoding>UTF-8</encoding>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
3、resource配置
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.xlsx</include>
</includes>
</resource>
</resources>
4、读取resources下的xlsx文件
 try {
//获取模板文件
File sourceFile = ResourceUtils.getFile("classpath:bankNameTemplate.xlsx");
//转换为文件流
BufferedInputStream fs = new BufferedInputStream(new FileInputStream(sourceFile));
//指定默认下载名称
String fileName = "XXX.xlsx";
//配置response的头
response.reset();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
try {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//循环从文件中读出数据后写出,完成下载
byte[] b = new byte[1024];
int len;
while ((len = fs.read(b)) != -1) {
response.getOutputStream().write(b, 0, len);
}
fs.close();
} catch (Exception e) {
logger.error("下载Excel模板异常", e);
}
5.前端请求
  window.location.href = "/exportExcelTemplate";  

最新文章

  1. ShineTime - 带有 CSS3 闪亮特效的缩略图相册
  2. JS 数字转换为大写金额
  3. 基于redis的分布式锁
  4. HTML5移动开发中的input输入框类型
  5. SPL學習之SplDoublyLinkedList
  6. C语言_函数【转】
  7. Working with Python subprocess - Shells, Processes, Streams, Pipes, Redirects
  8. UOJ#440. 【NOIP2018】填数游戏 动态规划
  9. 搭建docker私有仓库
  10. inheritCombinedParasitic.js
  11. BZOJ2743 HEOI2012采花(离线+树状数组)
  12. Logistic Regression – Geometric Intuition
  13. 【转】C# Graphics类详解
  14. 搭建自己的 Docker 私有仓库服务
  15. 数组实例 find和filter差异
  16. 证件照制作:使用PS打印一寸照片
  17. Rhel5.5配置Centos yum源
  18. VS调试_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse));崩溃原因及解决方法
  19. libevent源码深度剖析十
  20. 活动的生命周期 Android

热门文章

  1. libusb开发者指南
  2. jQuery file upload里面的_create的调用和_initEventHandlers的调用
  3. webpack安装大于4.x版本(没有配置webpack.config.js)
  4. leetcode-mid-backtracking-17. Letter Combinations of a Phone Number
  5. mysql命令使用2
  6. leetcode 27. 移除元素(python)
  7. python调用c/c++时传递结构体参数
  8. .NET中使用EF6与连接MYSQL
  9. 中国MOOC_零基础学Java语言_第5周 数组_1多项式加法
  10. java 发送 http post 和 get 请求(利用unirest)