接下来代码展示
1.添加easyExcel依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.3</version>
</dependency>
2.创建一个类似于实体的Bean
package com.zykj.common.util.bean;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class ExportReconciliationClearFormBean {
//标题
public String title;
//序号
public int number;
//日期
public String date;
//业务系统人数
public int number_of_business_system;
//业务系统金额
public BigDecimal business_system_amount;
//财务到账人数
public int number_of_people_in_the_account;
//财务到账金额
public BigDecimal financial_receipt_amount;
//人数差异
public int poor_number_of_people;
//金额差异
public BigDecimal difference_in_amount;
//业务系统人数合计
public int yw_people_count;
//业务系统金额合计
public BigDecimal yw_amount_count;
//财务到账人数合计
public int cw_people_count;
//财务到账金额合计
public BigDecimal cw_amount_count;
//人数差异合计
public int poor_number_of_people_count;
//金额差异合计
public BigDecimal difference_in_amount_count;
//备注
public String remarks;
//这里省略了get和set方法 记得添加
}
}
3.根据你的需求创建摸版
{xxx}是Map填充 xxx对应key value放所对应的值
{.xxx}是list填充 xxx对应着list的名称 如果是list<上面创建的bean> 那xxx对应bean的属性
4.后台Controller代码
/**
* 导出对账确认表
* qyh
*/
public void exportReconciliationClearForm() throws IOException, ParseException {
Map<String,Object> map = new HashMap<>();
List<ExportReconciliationClearFormBean> bean = new ArrayList<ExportReconciliationClearFormBean>();
String date = getPara("date");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//开始时间
String tartingTime = date.substring(0,date.indexOf(" -"));
//结束时间
String endTime = date.substring(date.lastIndexOf("- ")+1,date.length());
//系统类型 1职称 2计算机英语 3协会
String orderType = getPara("orderType");
map.put("tartingTime",sdf.parse(tartingTime.replace("/","-")));
map.put("endTime",sdf.parse(endTime.replace("/","-")));
map.put("orderType",orderType);
int randInt = (int) ((Math.random() * 9 + 1) * 1000);
String fileName = RdmUtils.replaceSign(endTime)+ randInt + ".zip";
getResponse().setContentType("APPLICATION/OCTET-STREAM");
//b.Content-Disposition 设置要被下载的文件名
getResponse().setHeader("Content-Disposition", "attachment;filename=" + fileName);
//获取输出流
ServletOutputStream out = getResponse().getOutputStream();
//计算机英语系统 报名 用书 证书
String computerEnglish = getPara("orderTypeTwo");
String[] computerEnglishType = computerEnglish.split(",");
List<File> listFile = new ArrayList