alibaba/easyexcel

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

Open

#3,848 opened on 2024年6月21日

GitHub で見る
 (2 comments) (0 reactions) (0 assignees)Java (7,599 forks)batch import
help wanted

Repository metrics

Stars
 (33,728 stars)
PR merge metrics
 (30d に merged PR はありません)

説明

你好, 目前在我在使用 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);`
    

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

谢谢。

コントリビューターガイド