DownExcelTemplateUtil.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.jkcredit.invoice.util;
  2. import javax.servlet.http.HttpServletResponse;
  3. /**
  4. * @description:
  5. * @author: sunzhaoning
  6. * @create: 2019-05-31 09:16
  7. * @version: V1.0
  8. **/
  9. public class DownExcelTemplateUtil {
  10. public static void downloadExcel(HttpServletResponse response,String fileName) {
  11. /* try {
  12. // 读到流中
  13. //文件的存放路径
  14. // InputStream inStream = new FileInputStream( CommonConstants.BASE_PATH + CommonConstants.TEMPLATE_PATH +fileName);
  15. // 设置输出的格式
  16. response.reset();
  17. response.setContentType("bin");
  18. response.addHeader("Content-Disposition",
  19. "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
  20. // 循环取出流中的数据
  21. byte[] b = new byte[200];
  22. int len;
  23. while ((len = inStream.read(b)) > 0) {
  24. response.getOutputStream().write(b, 0, len);
  25. }
  26. inStream.close();
  27. } catch (IOException e) {
  28. e.printStackTrace();
  29. }*/
  30. }
  31. }