private List<List<String>> getHeader(List<ProductCategory> categories) {
final String mainHead = LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy年MM月dd日") + "XXX";
List<String> head1 = new ArrayList<>();
head1.add(mainHead);
head1.add("区域");
List<String> head2 = new ArrayList<>();
head2.add(mainHead);
head2.add("序号");
List<String> head3 = new ArrayList<>();
head3.add(mainHead);
head3.add("用户");
List<String> head4 = new ArrayList<>();
head4.add(mainHead);
head4.add("具体 ");
List<List<String>> resHead = new ArrayList<>();
resHead.add(head1);
resHead.add(head2);
resHead.add(head3);
resHead.add(head4);
for (int i = 1; i < 9; i++) {
List<String> head5 = new ArrayList<>();
head5.add(mainHead);
head5.add("明细");
head5.add(i);
resHead.add(head5);
}
return resHead;
}
使用
//表头
List<List<String>> header = this.getHeader(categories);
//写入表头
EasyExcel.write(outputStream)
.head(header)
.sheet()
.doWrite(dataList)
;
}
效果图
![](https://i-blog.csdnimg.cn/blog_migrate/0ed5ae12c130a47e3e28252e48acc8b8.png)