- A+
所属分类:编程茶楼
共计 1325 个字符,预计需要花费 4 分钟才能阅读完成。
1)Excel模板表格如下 ExcelExportTemp.xlsx
2)Excel模板对应的实体类
public class ExcelDto implements Serializable {
private static final long serialVersionUID = 3014094398002798768L;
/**
* 账号
*/
@ExcelProperty(value = {"账号"})
private String account;
/**
* 账号姓名
*/
@ExcelProperty(value = {"账号姓名"})
private String name;
/**
* 邮箱
*/
@ExcelProperty(value = {"邮箱"})
private String email;
/**
* 密码
*/
@ExcelProperty(value = {"密码"})
private String password;
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
3)代码逻辑部分
//1,找出模板文件,并转化为输入流
ClassPathResource classPathResource = new ClassPathResource("static/ExcelExportTemp.xlsx");
InputStream inputStream = classPathResource.getInputStream();
//2,outputStream:要导出的文件的输出流;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ExcelWriter excelWriter = EasyExcel.write(outputStream).withTemplate(inputStream).build();
WriteSheet writeSheet = EasyExcel.writerSheet("工作表名").build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
//3,结束,否则得到的数组是空的
excelWriter.finish();
byte[] bytes = outputStream.toByteArray();
// 得到的字节数组,随你怎么操作也可以的
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫