easyExcel导出excel

/**
     * 导出EXCEL
     *
     * @throws FileNotFoundException
     */
    @RequestMapping("/excel")
    public void excel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        
         ExcelWriter writer = null;
            OutputStream outputStream = response.getOutputStream();
         try {
            //添加响应头信息
            response.setHeader("Content-disposition", "attachment; filename=" + "catagory.xls");
            response.setContentType("application/msexcel;charset=UTF-8");//设置类型
            response.setHeader("Pragma", "No-cache");//设置头
            response.setHeader("Cache-Control", "no-cache");//设置头
            response.setDateHeader("Expires", 0);//设置日期头

            //实例化 ExcelWriter
            writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLS, true);

            //实例化表单
            Sheet sheet = new Sheet(1, 0, QInformationModel.class);
            sheet.setSheetName("客户信息管理");

            //获取数据
//            PageUtils page = qInformationService.queryPage(params);
            List list = qInformationService.queryAll();

            //输出
            writer.write(list, sheet);
            writer.finish();
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                response.getOutputStream().close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        
    }

你可能感兴趣的:(个人笔记)