Maven依赖如下:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
Controller:
package com.excel.demo.controller;
import com.alibaba.excel.EasyExcel;
import com.excel.demo.vo.LedgerreRealFeeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author :Hj
* @date 2021/2/24 10:50
*/
@RestController
@RequestMapping("/person")
public class PersonControl {
@Autowired
private LedgerRealFeeService feeService;
@RequestMapping(value = "/getData")
public String test(){
//获取数据
List<LedgerreRealFeeVo> realFeeVos= feeService.getDataVo();
String filename = "D:\\Data\\Data.xlsx";
long start = System.currentTimeMillis();
//关键代码
EasyExcel.write(filename,LedgerreRealFeeVo.class).sheet("数据").doWrite(realFeeVos);
long finish = System.currentTimeMillis();
long timeElapsed=finish-start;
System.out.print(timeElapsed);
return "sucess";
}
}
VO:
package com.excel.demo.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author :Hj
* @date 2021/2/24 10:47
*/
public class LedgerreRealFeeVo {
@ExcelProperty(value = "业务号")
private Long sno;
@ExcelProperty(value = "任务号")
private String taskId;
@ExcelProperty(value = "类型")
private String certiType;
@ExcelProperty(value = "人员代码")
private String agentCode;
@ExcelProperty(value = "机构")
private String comCode;
@ExcelProperty(value = "业务性质")
private String businessNature;
@ExcelProperty(value = "团队代码")
private String teamCode;
@ExcelProperty(value = "团队名称")
private String teamName;
@ExcelProperty(value = "日期")
private Date realPayDate;
@ExcelProperty(value = "afee")
private BigDecimal afee;
@ExcelProperty(value = "bfee")
private BigDecimal bfee;
@ExcelProperty(value = "cfee")
private BigDecimal cfee;
public Long getSno() {
return sno;
}
public void setSno(Long sno) {
this.sno = sno;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getCertiType() {
return certiType;
}
public void setCertiType(String certiType) {
this.certiType = certiType;
}
public String getAgentCode() {
return agentCode;
}
public void setAgentCode(String agentCode) {
this.agentCode = agentCode;
}
public String getComCode() {
return comCode;
}
public void setComCode(String comCode) {
this.comCode = comCode;
}
public String getBusinessNature() {
return businessNature;
}
public void setBusinessNature(String businessNature) {
this.businessNature = businessNature;
}
public String getTeamCode() {
return teamCode;
}
public void setTeamCode(String teamCode) {
this.teamCode = teamCode;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public Date getRealPayDate() {
return realPayDate;
}
public void setRealPayDate(Date realPayDate) {
this.realPayDate = realPayDate;
}
public BigDecimal getAfee() {
return afee;
}
public void setAfee(BigDecimal afee) {
this.afee = afee;
}
public BigDecimal getBfee() {
return bfee;
}
public void setBfee(BigDecimal bfee) {
this.bfee = bfee;
}
public BigDecimal getCfee() {
return cfee;
}
public void setCfee(BigDecimal cfee) {
this.cfee = cfee;
}
}
1000960行数据耗时: