当前位置 : 主页 > 编程语言 > java >

spring boot导出excel时header设置

来源:互联网 收集:自由互联 发布时间:2021-06-28
导出excel @RequestMapping(value = "/bill/list/download/{store}/{from}/{to}/{type}/{menthod}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public void downloadBillList(@PathVariable("store") String store,
导出excel
@RequestMapping(value = "/bill/list/download/{store}/{from}/{to}/{type}/{menthod}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void downloadBillList(@PathVariable("store") String store,
                                 @PathVariable("from") String from,
                                 @PathVariable("to") String to,
                                 @PathVariable("type") String type,
                                 @PathVariable("menthod") String menthod,
                                 HttpServletResponse response) throws Exception {
        String fileName = "bill.xls";// 文件名
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode(fileName, "UTF-8"));
        ExcelBulider excelBulider = new ExcelBulider();
        excelBulider.billList = billService.adminFindByStoreId(store, from, to, type,menthod);
        //System.out.println("billList:"+billService.adminFindByStoreId(page,storeId));
        HSSFWorkbook workbook = excelBulider.build();
        workbook.write(response.getOutputStream());
    }
上一篇:加载freemarker模板
下一篇:adapter
网友评论