将工作簿响应到浏览器下载

public static void writeWorkbookToResponse(HttpServletResponse response, Workbook wb, String fileName){
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName+".xlsx").getBytes(), StandardCharsets.ISO_8859_1));
        try (OutputStream os = response.getOutputStream()) {
            wb.write(os);
            wb.close();
            os.flush();
        } catch (Exception e){
            log.error(e.getMessage());
        }
    }
posted @ 2023-03-28 11:45  晚风没有颜色  阅读(28)  评论(0编辑  收藏  举报