栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

EasyPoi多sheet导出

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

EasyPoi多sheet导出

测试类

//准备数据比例
        UserVo userVo1= UserVo.builder().userName("cxk").id(1).sex(2).img("xx.img").build();
        UserVo userVo2= UserVo.builder().userName("lbw").id(2).sex(1).img("xx").build();
        UserVo userVo3= UserVo.builder().userName("xz").id(3).sex(2).build();
        UserVo userVo4= UserVo.builder().userName("芜湖").id(4).sex(2).build();
        UserVo userVo5= UserVo.builder().userName("起飞").id(5).sex(2).build();
        UserVo userVo6= UserVo.builder().userName("kk").id(6).sex(2).build();
        UserVo userVo7= UserVo.builder().userName("ex").id(7).sex(2).build();
        ClassVo classOne= ClassVo.builder().classId(1).name("一班").build();
        ClassVo classTwo= ClassVo.builder().classId(2).name("二班").build();
        List a= Lists.newArrayList(userVo1, userVo2, userVo3);
        List b= Lists.newArrayList(userVo4, userVo5, userVo6, userVo7);
        classOne.setUserList(a);
        classTwo.setUserList(b);
        List classVos=Lists.newArrayList(classOne, classTwo);
        List userVos=Lists.newArrayList(userVo1, userVo2, userVo3, userVo4, userVo5);
        //准备第一个sheet页,填充班级数据
        ExportParams classParams = new ExportParams();
        classParams.setSheetName("班级详情表");
        Map classExportMap = new HashMap<>();
        classExportMap.put("title",classParams);
        classExportMap.put("data",classVos);
        classExportMap.put("entity",ClassVo.class);
        //准备第二个sheet页,填充学生数据
        ExportParams studentParams = new ExportParams();
        studentParams.setSheetName("学生详情表");
        Map studentExportMap = new HashMap<>();
        studentExportMap.put("title",classParams);
        studentExportMap.put("data",userVos);
        studentExportMap.put("entity",UserVo.class);
        //将两个sheet变成一个集合
        List> sheetsList = new ArrayList<>();
        sheetsList.add(classExportMap);
        sheetsList.add(studentExportMap);
        //导出
        Workbook workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
        FileOutputStream fos = new FileOutputStream("班级详情.xls");
        workbook.write(fos);
        fos.close();

班级实体类

@Data
@Builder
public class ClassVo {
    @Excel(name = "班级id",needMerge = true,width = 12)
    private Integer classId;
    @Excel(name = "班级名称",orderNum = "1",needMerge = true)
    private String name;
    @ExcelCollection(name = "学生",orderNum = "2")
    private List userList;
}

学生实体类

@Data
@Builder
@AllArgsConstructor
public class UserVo {
    @Excel(name="姓名",orderNum = "1")
    private String userName;
    @Excel(name = "id")
    private Integer id;
    @Excel(name = "性别",replace = {"男_1","女_2"},orderNum = "3")
    private Integer sex;
    @Excel(name = "头像" ,suffix = ".img")
    private String img;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/321577.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号