zoukankan      html  css  js  c++  java
  • 下载excel模板

    /*
    * 下载客户档案模板
    * @param response
    */
    @ApiOperation(value = "下载客户档案模板", notes = "下载客户档案模板")
    @PostMapping(value = "/downloadCustomerTemplate")
    public void downloadCustomerTemplate(HttpServletResponse response) {
    fis = null;
    try {
    String filePath = "C:/test/customer_excel_imp.xls";
    File file = new File(filePath);
    if (!file.exists()) {
    response.sendError(404, "File not found!");
    } else {
    // 取得文件名。
    String filename = file.getName();
    // 以流的形式下载文件。
    fis = new BufferedInputStream(new FileInputStream(filePath));
    byte[] buffer = new byte[fis.available()];
    // 清空response
    fis.read(buffer);
    // JSONP 解决跨域问题
    response.reset();
    response.addHeader("Access-Control-Allow-Origin", "*");
    response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
    response.addHeader("Access-Control-Allow-Headers", "Content-Type");
    // 设置response的Header
    response.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"iso-8859-1"));
    response.addHeader("Content-Length", "" + file.length());
    OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
    response.setContentType("application/octet-stream");
    toClient.write(buffer);
    toClient.flush();
    toClient.close();
    fis.close();
    }
    } catch (IOException ex) {
    logger.error("异常:",ex.getMessage());
    }
    }
  • 相关阅读:
    写了个批量下载抖音无水印视频的小软件。
    ffmpeg转换参数码
    WPF
    使用EF的Code First模式创建模型
    桌面置顶显示服务器信息
    Assert.assertEquals
    XML报文解析思路
    定时任务,cron七域
    检查网络是否通畅
    Ngnix运行vue项目
  • 原文地址:https://www.cnblogs.com/pan-my/p/11052899.html
Copyright © 2011-2022 走看看