java excel导出

java excel导出,第1张

java excel导出

jar 内部可下载
文件在 resources/excelTemplate/下


    @GetMapping("file")
    public ResponseEntity fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
        InputStream is = null;
        try {
            response.reset();
            is = new ClassPathResource(File.separator + "excelTemplate" + File.separator + fileName).getInputStream();

            response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            response.addHeader("charset", "utf-8");
            response.addHeader("Pragma", "no-cache");
            String encodeName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
            response.setHeader("Content-Disposition", "attachment; filename="" + encodeName + ""; filename*=utf-8''" + encodeName);

            IOUtils.copy(is, response.getOutputStream());
            response.flushBuffer();

        } catch (Exception e) {
            log.error("下载文件失败", e);
        } finally {
            IOUtils.closeQuietly(is);
        }
        return null;
    }




欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3978349.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-21
下一篇 2022-10-21

发表评论

登录后才能评论

评论列表(0条)

保存