packagecom.atgugui.excel;importcom.alibaba.excel.annotation.ExcelProperty;importlombok.Data;@DatapublicclassDemoData{@ExcelProperty(value ="学生编号", index =0)privateInteger sno;@ExcelProperty(value ="学生姓名", index =1)privateString sname;}
3.执行写入excel操作
packagecom.atgugui.excel;importcom.alibaba.excel.EasyExcel;importjava.util.ArrayList;importjava.util.List;publicclassTestEasyExcel{publicstaticvoidmain(String[] args){// 实现excel写操作//1 设置写入文件夹地址和excel文件名称String filename ="F:\\test.xlsx";// 2.调用easyexcel里面的方法实现写操作// write方法两个参数,第一个参数文件路径名称,第二个参数实体类classEasyExcel.write(filename,DemoData.class).sheet("学生列表").doWrite(getData());}privatestaticList<DemoData>getData(){List<DemoData> list =newArrayList<>();for(int i =0; i <10; i++){DemoData data =newDemoData();
data.setSno(i);
data.setSname("lucy"+ i);
list.add(data);}return list;}}