浏览器下载excel

 /**
     * 浏览器下载excel
     *
     * @param fileName 文件名称
     * @param wb Workbook
     * @param response 响应response
     */
    private static void buildExcelDocument(String fileName, Workbook wb, HttpServletResponse response){
        try {
            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
            response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(fileName, "utf-8"));
            response.flushBuffer();
            wb.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
posted @ 2020-08-12 20:06  wqkeep  阅读(237)  评论(0编辑  收藏  举报