alibaba/easyexcel

如何支持内容单元格背景色交替显示

Open

#3 848 ouverte le 21 juin 2024

Voir sur GitHub
 (2 commentaires) (0 réactions) (0 assignés)Java (7 599 forks)batch import
help wanted

Métriques du dépôt

Stars
 (33 728 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

你好, 目前在我在使用 EasyExcel (版本 3.3.4) 结合 JDK 17 生成 Excel 文件。

有个需求:内容行设置交替的背景颜色,这样每一行都有不同的背景颜色,以两种指定的颜色交替显示。这样可以帮助用户更容易区分每一行,避免看错行。

` // 创建头部的样式策略 WriteCellStyle headWriteCellStyle = new WriteCellStyle();

headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);

WriteFont headFont = new WriteFont();
headFont.setFontHeightInPoints((short) 14); 
headWriteCellStyle.setWriteFont(headFont);

// 创建内容的样式策略
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
WriteFont contentFont = new WriteFont();
contentFont.setFontHeightInPoints((short) 12); 
contentWriteCellStyle.setWriteFont(contentFont);

// 样式策略
HorizontalCellStyleStrategy horizontalCellStyleStrategy =
    new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);`
    

上面是我写的样式策略,
我应该怎么改,才能实现「内容行设置交替的背景颜色」的效果。

谢谢。

Guide contributeur