easyExcel 多sheet导出 与 读取

导出

     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ExcelWriter excelWriter = EasyExcel.write(byteArrayOutputStream).build();
        WriteSheet studentSheet =
                EasyExcel.writerSheet(0, "学生信息").head(Student.class).build();
        WriteSheet grateSheet =
                EasyExcel.writerSheet(1, "班级信息").head(Grate.class).build();
        excelWriter.write(studentList, studentSheet)
                .write(grateList.get(), grateSheet);
        excelWriter.finish();

读取

//一次读取多个sheet页
ExcelReader excelReader = EasyExcel.read(in).build();
StringBuffer excelCode = new StringBuffer();
ReadSheet sheet1 = EasyExcel.readSheet("1").headRowNumber(0).registerReadListener(new CheckHideSheetCodeReadListener(excelCode)).build();

List importDTOList = Lists.newArrayList();
ReadSheet sheet2 = EasyExcel.readSheet("2").headRowNumber(2).head(Object123ImportDTO.class)
        .registerReadListener(new ImportReadListener1223(importDTOList)).build();
excelReader.read(sheet1, sheet2);
excelReader.finish();

你可能感兴趣的:(java,开发语言,excel)