1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > poi导出excel色阶设置工具类

poi导出excel色阶设置工具类

时间:2022-09-02 04:29:04

相关推荐

poi导出excel色阶设置工具类

在使用POI导出excel时,如何给某行或者某列设置色阶呢?直接上代码:

/*** sheet 设置色阶 在填充数据之后设置色阶* @param sheet*/public static void setColourScales(Sheet sheet) {SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();// 三色色阶 红白蓝 此处为设置B行3列 - J行3列CellRangeAddress[] regions = new CellRangeAddress[] {CellRangeAddress.valueOf("B3:J3") };ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingColorScaleRule();ColorScaleFormatting cs2 = rule2.getColorScaleFormatting();// 三色色阶标志cs2.setNumControlPoints(3);// 设置最小色阶cs2.getThresholds()[0].setRangeType(ConditionalFormattingThreshold.RangeType.MIN);// 设置两个颜色递进的形式 此处为百分比 即前百分之50为红白;后百分之50为白蓝cs2.getThresholds()[1].setRangeType(ConditionalFormattingThreshold.RangeType.PERCENTILE);cs2.getThresholds()[1].setValue(50d);// 设置最大色阶cs2.getThresholds()[2].setRangeType(ConditionalFormattingThreshold.RangeType.MAX);// 分别设置颜色(该颜色编码,前两位为透明度,后面六位为颜色)((ExtendedColor)cs2.getColors()[0]).setARGBHex("FFF8696B");((ExtendedColor)cs2.getColors()[1]).setARGBHex("FFFCFCFF");((ExtendedColor)cs2.getColors()[2]).setARGBHex("FF5A8AC6");sheetCF.addConditionalFormatting(regions, rule2);// 两色色阶 蓝绿 此处为B行4列 - B行20列regions = new CellRangeAddress[] {CellRangeAddress.valueOf("B4:B20") };ConditionalFormattingRule rule3 = sheetCF.createConditionalFormattingColorScaleRule();ColorScaleFormatting cs3 = rule3.getColorScaleFormatting();// 两色色阶标志cs3.setNumControlPoints(2);// 设置最小色阶cs3.getThresholds()[0].setRangeType(ConditionalFormattingThreshold.RangeType.MIN);// 设置最大色阶cs3.getThresholds()[1].setRangeType(ConditionalFormattingThreshold.RangeType.MAX);// 分别设置颜色(该颜色编码,前两位为透明度,后面六位为颜色)((ExtendedColor)cs3.getColors()[0]).setARGBHex("FF5A8AC6");((ExtendedColor)cs3.getColors()[1]).setARGBHex("FF63BE7B");sheetCF.addConditionalFormatting(regions, rule3);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。