public List<List<String>> head(DyaqModel exportList){
String format = new SimpleDateFormat("yyyy-MM-dd").format(exportList.getQsdjsj());
String format2 = new SimpleDateFormat("yyyy-MM-dd").format(exportList.getJsdjsj());
//初始化第一行表头
String bigTitle=format+"至"+format2+"不动产登记费用清单";
//创建表头集合
List<List<String>>head=new ArrayList<>();
//这里的每一个list都是代表一列,按照顺序来,相同的名称会自动合并单元格,比如说两个序号,
//就是把第第一列的第二第三格合并到了一起
//然后行单元格合并是同理的,可以看到bigTitle每一个list都有,都是在第一个,说明每一列的
//第一个单元格都是这个值,所以最终的效果就是你生成的表格第一行全部合并,然后可以展示大表
//头,
//第一列
List<String> title=new ArrayList<>(Arrays.asList(bigTitle,"序号","序号","序号","序号","序号","序号","序号","序号","序号"));
head.add(title);
//第二列
List<String> title1=new ArrayList<>(Arrays.asList(bigTitle,"业务号","业务号","业务号","业务号","业务号","业务号","业务号","业务号","业务号"));
head.add(title1);
//第三列
List<String> title2=new ArrayList<>(Arrays.asList(bigTitle,"抵押权人","抵押权人","抵押权人","抵押权人","抵押权人","抵押权人","抵押权人","抵押权人","抵押权人"));
head.add(title2);
//第四列
List<String> title3=new ArrayList<>(Arrays.asList(bigTitle,"抵押权","抵押权","抵押权","抵押权","抵押权","抵押权","抵押权","抵押权","抵押权"));
head.add(title3);
//第五列
List<String> title4=new ArrayList<>(Arrays.asList(bigTitle,"坐落","坐落","坐落","坐落","坐落","坐落","坐落","坐落","坐落"));
head.add(title4);
//第六列
List<String> title5=new ArrayList<>(Arrays.asList(bigTitle,"抵押金额(万元)","抵押金额(万元)","抵押金额(万元)","抵押金额(万元)","抵押金额(万元)","抵押金额(万元)","抵押金额(万元)","抵押金额(万元)","抵押金额(万元)"));
head.add(title5);
//第七列
List<String> title6=new ArrayList<>(Arrays.asList(bigTitle,"登记时间","登记时间","登记时间","登记时间","登记时间","登记时间","登记时间","登记时间","登记时间"));
head.add(title6);
//第八列
List<String> title7=new ArrayList<>(Arrays.asList(bigTitle,"登记费(元)","登记费(元)","登记费(元)","登记费(元)","登记费(元)","登记费(元)","登记费(元)","登记费(元)","登记费(元)"));
head.add(title7);
//第九列
List<String> title8=new ArrayList<>(Arrays.asList(bigTitle,"交易服务费(元)","交易服务费(元)","交易服务费(元)","交易服务费(元)","交易服务费(元)","交易服务费(元)","交易服务费(元)","交易服务费(元)","交易服务费(元)"));
head.add(title8);
//最后直接把这些生成的表头集合返回就行了
return head;
}
}
private void exportmaps(List<List<String>> listList, String tittle, List<DyaqModelExp> dyaqModelExpList, String reportName, HttpServletResponse response, BigDecimal djf, BigDecimal jyfwf) {
response.setContentType("application/vnd.ms-excel; charset=utf-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=reportName.xlsx");
List<List<String>> head = new ArrayList<>();
List<String> strings = new ArrayList<>();
strings.add(tittle);
head.add(strings);
LinkedList<DyaqModelExp> list = new LinkedList<>(dyaqModelExpList);
DyaqModelExp modelExp = new DyaqModelExp();
modelExp.setDjf(djf.toString());
modelExp.setDjsj("登记费合计:" );
// modelExp.setJyfwf("交易服务费合计:" + jyfwf.toString());
list.add(modelExp);
try {
EasyExcelFactory.write(response.getOutputStream(), DyaqModelExp.class).head(listList).sheet(tittle).doWrite(list);
} catch (IOException e) {
throw new RuntimeException(reportName + "文件导出异常");
}
}
重点在于:
EasyExcelFactory.write(response.getOutputStream(),
DyaqModelExp.class).head(listList).sheet(tittle).doWrite(list);
调用head方法
最后成图: