🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
![](https://img.kancloud.cn/fd/1a/fd1af577788a3ff4e3009288d2aafe1f_1696x264.jpg) **1. 创建对应的实体类** ```java @Data @AllArgsConstructor //头背景设置成红色 IndexedColors.RED.getIndex() @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 10) //头字体大小设置成20,字体为雅黑 @HeadFontStyle(fontHeightInPoints = 20, fontName = "雅黑") //内容的背景设置成绿色 IndexedColors.GREEN.getIndex() @ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 17) //内容字体大小设置成20,字体为宋体 @ContentFontStyle(fontHeightInPoints = 20, fontName = "宋体") public class Computer { /** 上面的@XXXStyle注解也可以用在属性上,来覆盖上面设置的样式 */ //name列的头背景设置成粉红 IndexedColors.PINK.getIndex() @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 14) private String name; private Double price; @DateTimeFormat("yyyy-MM-dd HH:mm:ss") private Date createDate; } ``` **2. 写入数据** ```java @Test public void write01() { List<Computer> dataList = Lists.newArrayList(); Computer computer01 = new Computer("电脑01", 8999.0, new Date()); Computer computer02= new Computer("电脑02", 9000.0, new Date()); dataList.add(computer01); dataList.add(computer02); EasyExcel.write("e:/upload/easyexcel/002.xlsx", Computer.class).sheet("Sheet1").doWrite(dataList); } ``` **** 更多用法参考官方文档:https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write