easyexcel怎么设置头样式
时间: 2023-08-15 11:25:37 浏览: 103
在使用easyexcel进行Excel文件操作时,可以通过以下方式设置头部样式:
1. 创建样式对象:
```
WriteCellStyle headStyle = new WriteCellStyle();
```
2. 设置字体样式:
```
WriteFont headFont = new WriteFont();
headFont.setFontName("微软雅黑");
headFont.setFontHeightInPoints((short) 12);
headFont.setBold(true);
headStyle.setWriteFont(headFont);
```
3. 设置背景颜色:
```
headStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
headStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
```
4. 将样式对象设置到头部单元格中:
```
WriteSheet writeSheet = EasyExcel.writerSheet().build();
writeSheet.setColumnWidth(0, 20);
writeSheet.setColumnWidth(1, 20);
writeSheet.setColumnWidth(2, 20);
writeSheet.setColumnWidth(3, 20);
List<List<String>> head = new ArrayList<List<String>>();
head.add(Arrays.asList("姓名", "性别", "年龄", "地址"));
writeSheet.setHead(head);
writeSheet.setHeadStyle(headStyle);
```
以上代码中,`setHeadStyle` 方法就是将头部样式对象设置到 Excel 文件中的头部单元格中。
阅读全文