SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
String date = sdf.format(new Date());
String fileName="成本系统"+date+".xlsx";
// String fileName = "D:\\add\\test.xlsx"; 测试导入到本地磁盘
OutputStream out = null;
try {
out = new FileOutputStream(fileName);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
ExcelWriter excelwriter = EasyExcel.write(out).build();
excelwriter.write(DatabaseInfoDtoList,EasyExcel.writerSheet().head(DatabaseInfoDto.class).build());
excelwriter.finish();
需要准备好要导出的数据DatabaseInfoDtoList 和 easyexcel依赖哦
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.4</version>
</dependency>