List<List<String>> list = new ArrayList<List<String>>(); List<String> head0 = new ArrayList<String>(); head0.add("VIN"); list.add(head0); if("1".equals(type)){ List<String> head1 = new ArrayList<String>(); head1.add("预计时间"); list.add(head1); } try { WriteCellStyle headWriteCellStyle = new WriteCellStyle(); WriteFont contentWriteFont = new WriteFont(); contentWriteFont.setColor(IndexedColors.RED.index); headWriteCellStyle.setWriteFont(contentWriteFont); EasyExcel.write(response.getOutputStream()) .registerWriteHandler(new HorizontalCellStyleStrategy(headWriteCellStyle, new WriteCellStyle())) // 这里放入动态头 .head(list).sheet("模板") // 当然这里数据也可以用 List<List<String>> 去传入 .doWrite(null); } catch (IOException ex) { ex.printStackTrace(); }
标签:WriteCellStyle,List,EasyExcel,list,表头,add,new,模板 From: https://www.cnblogs.com/lxnv587/p/17524735.html