EasyExcel是一个基于Java的简单、省内存的读写Excel的开源项目。在尽量节约内存的状况下支持读写百M的Excel。 64M内存1分钟内读取75M(46W行25列)的Excel,固然还有急速模式能更快,可是内存占用会在100M多一点git
easyexcel
,已上传至 maven 仓库
<dependency>
<groupId>com.pig4cloud.excel</groupId>
<artifactId>excel-spring-boot-starter</artifactId>
<version>0.0.2</version>
</dependency>
复制代码
只须要在 Controller
层返回 List 并增长 @ResponseExcel
注解便可github
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ResponseExcel {
String name() default "";
ExcelTypeEnum suffix() default ExcelTypeEnum.XLSX;
String password() default "";
String[] sheet() default {};
boolean inMemory() default false;
String template() default "";
String[] include() default {};
String[] exclude() default {};
Class<? extends WriteHandler>[] writeHandler() default {};
Class<? extends Converter>[] converter() default {};
}
复制代码
sheet
, 所有字段导出
@ResponseExcel(name = "lengleng", sheet = "demoList")
@GetMapping("/e1")
public List<DemoData> e1() {
List<DemoData> dataList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
DemoData data = new DemoData();
data.setUsername("tr1" + i);
data.setPassword("tr2" + i);
dataList.add(data);
}
return dataList;
}
// 实体对象
@Data
public class DemoData {
private String username;
private String password;
}
复制代码
@Data
public class DemoData {
@ColumnWidth(50) // 定义宽度
@ExcelProperty("用户名") // 定义列名称
@ContentStyle(fillPatternType = FillPatternType.SOLID_FOREGROUND, fillForegroundColor = 40)
private String username;
@ExcelProperty("密码")
private String password;
}
复制代码
@Data
public class DemoData {
@ColumnWidth(50) // 定义宽度
@ExcelProperty("用户名") // 定义列名称
@ContentStyle(fillPatternType = FillPatternType.SOLID_FOREGROUND, fillForegroundColor = 40)
private String username;
@ExcelProperty("密码")
private String password;
}
复制代码
@ResponseExcel(name = "lengleng", sheet = {"第一个sheet","第二个sheet"})
@GetMapping("/e1")
public List<List<DemoData>> e1() {
List<List<DemoData>> lists = new ArrayList<>();
lists.add(list());
lists.add(list());
return lists;
}
复制代码
@ResponseExcel(name = "lengleng", sheet = "sheetName",password = "lengleng")
@GetMapping("/e1")
public List<List<DemoData>> e1() {
List<List<DemoData>> lists = new ArrayList<>();
lists.add(list());
lists.add(list());
return lists;
}
复制代码
@ResponseExcel(name = "模板测试excel", sheet = "sheetName",template = "example.xlsx")
@GetMapping("/e1")
public List<DemoData> e1() {
return list();
}
复制代码
『★★★★★』 基于Spring Boot 2.二、 Spring Cloud Hoxton & Alibaba、 OAuth2 的RBAC 权限管理系统 web