直接上代码:
public static void main(String[] args) {// 设置excel工作簿ExcelWriter excelWriter = EasyExcel.write("F:\\excel\\a.xls").build();List<User> userList = new ArrayList<>();userList.add(new User("lisi", "12"));userList.add(new User("wangWu", "15"));userList.add(new User("zhaoLiu", "22"));ExcelWriterSheetBuilder userExcelSheet = new ExcelWriterSheetBuilder();userExcelSheet.sheetName("学生信息");userExcelSheet.sheetNo(0);excelWriter.write(userList, userExcelSheet.build());List<ClassInfo> classInfoList = new ArrayList<>();classInfoList.add(new ClassInfo("1班", "22"));classInfoList.add(new ClassInfo("2班", "32"));ExcelWriterSheetBuilder classExcelSheet = new ExcelWriterSheetBuilder();classExcelSheet.sheetName("班级信息");classExcelSheet.sheetNo(1);excelWriter.write(classInfoList, classExcelSheet.build());excelWriter.finish();}
注意:
当设置完sheet时最后必须调用finish
方法不然当你打开excel时就会