导包
java
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.3</version>
</dependency>
内容
java
List<类> limspjreport = 值;
String fileName = sdf.format(new Date()) + "-结果汇集表-" + System.currentTimeMillis() + ".xlsx";
File excelFile = new File(fileName);
EasyExcel.write(fileName).head(head()).sheet("结果").registerWriteHandler(new CustomWidthStyleStrategy()).doWrite(dataList(limspjreport));
private List<List<String>> head() {
List<List<String>> list = ListUtils.newArrayList();
List<String> head0 = ListUtils.newArrayList();
head0.add("条码号");
List<String> head1 = ListUtils.newArrayList();
head1.add("小项代码");
List<String> head2 = ListUtils.newArrayList();
head2.add("项目名称");
List<String> head3 = ListUtils.newArrayList();
head3.add("参考范围");
List<String> head4 = ListUtils.newArrayList();
head4.add("检验结果");
List<String> head5 = ListUtils.newArrayList();
head5.add("高低标记:g,d,z,bd,bg,阴性,阳性");
list.add(head0);
list.add(head1);
list.add(head2);
list.add(head3);
list.add(head4);
list.add(head5);
return list;
}
private List<List<Object>> dataList(List<类> list) {
List<List<Object>> list = ListUtils.newArrayList();
tq(list, list);
return list;
}
private void tq(List<类> list, List<List<Object>> list) {
for (LIMSPJREPORT limspjreportolds : limspjreportold) {
List<Object> data = ListUtils.newArrayList();
Map<String, String> map = dz(limspjreportolds.getPURPOSENAME());
if (map.containsKey("code") && map.containsKey("name")){
data.add(limspjreportolds.getSENDCODE());
data.add(map.get("code"));
data.add(map.get("name"));
data.add("");
data.add(limspjreportolds.getFINALRESULT());
data.add("");
list.add(data);
}
}
}