easypoi 多sheet导出

        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>3.2.0</version>
        </dependency>

参考代码:

 public String export(){

        Workbook workBook = null;
        try {

//
            List<Map<String, Object>> sheetsList = new ArrayList<>();

            List<DeptUtil> exportList = exportService.exportList();

            // 创建参数对象(用来设定excel得sheet得内容等信息)
            ExportParams deptExportParams = new ExportParams();
            // 设置sheet得名称
            deptExportParams.setSheetName("员工报表1");
            // 创建sheet1使用得map
            Map<String, Object> deptExportMap = new HashMap<>();
            // title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
            deptExportMap.put("title", deptExportParams);
            // 模版导出对应得实体类型
            deptExportMap.put("entity", DeptUtil.class);
            // sheet中要填充得数据
            deptExportMap.put("data", exportList);
            sheetsList.add(deptExportMap);

            // 创建参数对象(用来设定excel得sheet得内容等信息)
            ExportParams empExportParams = new ExportParams();
            empExportParams.setSheetName("员工报表2");
            // 创建sheet2使用得map
            Map<String, Object> empExportMap = new HashMap<>();
            empExportMap.put("title", empExportParams);
            empExportMap.put("entity", DeptUtil.class);
            empExportMap.put("data", exportList);
            sheetsList.add(empExportMap);


//             执行方法
            workBook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
            fileName = URLEncoder.encode("员工报表导出", "UTF-8");
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            workBook.write(outputStream);
            outputStream.flush();
            byte[] byteArray = outputStream.toByteArray();
            excelStream = new ByteArrayInputStream(byteArray,0,byteArray.length);
            outputStream.close();

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(workBook != null) {
                try {
                    workBook.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return "success";
    }

官方文档:http://easypoi.mydoc.io/

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1-------- 走进前端 2-------- jQuery 3-------- CSS 4-------- A...
    依依玖玥阅读 2,366评论 0 34
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    小迈克阅读 3,063评论 1 3
  • 综合类 综合类 地址前端知识体系 http://www.cnblogs.com/sb19871023/p/3894...
    飞菲fly阅读 949评论 0 3
  • 我再也不要失去你了
    棱长四镜阅读 196评论 0 2
  • 在漫长的街道上,有一个人在缓慢的行走,她四周环绕着各种各样的怪物,怪物们因一些特殊原因无法靠近他的身边。 随着...
    无怠阅读 176评论 0 1