https://programmer.group/easyexcel-java-api-usage.html
public class ExcelEasyWrite { public static void main(String[] args) { /** * pathName File path to write * head Encapsulates the type of entity written * return Written workbook object */ // Workbook object ExcelWriterBuilder writerBuilder = EasyExcel.write("/Users/hudu/Documents/Study/EasyExcel/write.xlsx", Student.class); // Worksheet object ExcelWriterSheetBuilder sheet = writerBuilder.sheet(); // Prepare data List<Student> students = initData(); // write sheet.doWrite(students); } private static List<Student> initData() { ArrayList<Student> students = new ArrayList<>(); for (int i = 10; i < 20; i++) { Student student = new Student(); student.setName("test"+i); student.setBirthday(new Date()); student.setGender("male"); students.add(student); } return students; } }
@Data @NoArgsConstructor @AllArgsConstructor // Globally define column width @ColumnWidth(10) // Content line height //@ContentRowHeight(10) // Header row height @HeadRowHeight(20) public class Student { /** * value Field name * index Column order */ @ExcelProperty(value = {"Student information sheet","full name"},index = 0) private String name; @ExcelProperty(value = {"Student information sheet","date of birth"},index = 2) @DateTimeFormat("YYYY-MM-dd") @ColumnWidth(20) private Date birthday; @ExcelProperty(value = {"Student information sheet","Gender"},index = 1) private String gender; /** * Ignore field */ @ExcelIgnore private String id;