easyexcel 表头样式
时间: 2023-07-20 22:39:11 浏览: 69
您可以使用 EasyExcel 提供的 `WriteCellStyle` 类来设置表头样式。以下是一个示例代码:
```java
// 创建表头样式
WriteCellStyle headStyle = EasyExcel.writeCellStyle()
.fillPatternType(FillPatternType.SOLID_FOREGROUND)
.fillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex())
.borderLeft(BorderStyle.THIN)
.borderRight(BorderStyle.THIN)
.borderTop(BorderStyle.THIN)
.borderBottom(BorderStyle.THIN)
.build();
// 写入表头数据
List<List<String>> head = new ArrayList<>();
head.add(Arrays.asList("姓名", "年龄", "性别", "地址"));
// 写入 Excel
EasyExcel.write(fileName, DemoData.class)
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.head(head)
.headStyle(headStyle)
.sheet("Sheet1")
.doWrite(dataList);
```
在上面的示例中,我们使用 `WriteCellStyle` 类创建了一个表头样式 `headStyle`,并将其作为参数传递给 `headStyle()` 方法,以应用于表头。您可以根据需要调整 `WriteCellStyle` 类的属性来设置更多样式。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)