失效链接处理 |
阿里EasyExcel的操作 PDF 下载
本站整理下载:
提取码:8ses
相关截图:
主要内容:
阿里EasyExcel的操作
第一步:建立简单的maven项目,导入依赖
第二步:新建一个实体类进行操作
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.2.3</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> </dependency> </dependencies> 123456789101112131415161718 package com.aaa; import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.util.Date; /* 12345678910
第三步:数据的写入
3.1 普通写入 ** 创建用户模版 * */ @Data @NoArgsConstructor @AllArgsConstructor public class User { //表格的属性名称,index可以进行排序 从0开始排序 @ExcelProperty(value = "用户编号",index = 0) private Integer userId; @ExcelProperty(value = "姓名",index = 1) private String userName; @ExcelProperty(value = "性别",index = 3) private String gender; @ExcelProperty(value = "工资",index = 2) private Double salary; @ExcelProperty(value = "入职时间",index = 4) private Date date; } 111213141516171819202122232425262728293031 package com.test; import com.aaa.User; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.builder.ExcelWriterBuilder; import com.alibaba.excel.write.metadata.WriteSheet; import org.junit.Test; import java.util.*; public class WriteTest { /* 简单写方式一: 123456789101112131415
* */ @Test public void test01(){ //创建一个Excel文档 String fileName="user1.xlsx"; //根据User模版构造数据 List<User> list=new ArrayList<>(); User user=new User(1,"小明","男",12000.12,new Date()); User user1=new User(2,"小米","男",12000.12,new Date()); User user2=new User(3,"小红","男",12000.12,new Date()); User user3=new User(4,"小张","男",12000.12,new Date()); list.add(user); list.add(user1); list.add(user2); list.add(user3); //向表格中写数据 EasyExcel.write(fileName,User.class).sheet("用户信 息模版").doWrite(list); }/** 简单方式写方式二 * */ @Test public void test02(){ //创建一个Excel文档 String fileName="user2.xlsx"; //根据User模版构造数据 List<User> list=new ArrayList<>(); User user=new User(1,"小明","男",12000.12,new Date()); 1617181920212223242526272829303132333435363738394041424344454647
|