Apache POI for XSLX 3-color scale rule, How to define these method createConditionalFormattingRule() & class ConditionalFormattingThreshold.RangeType?

做~自己de王妃 提交于 2019-12-11 04:19:19

问题


This method createConditionalFormattingColorScaleRule() is not available in any of POI releases but explained in this link Conditional Formatting Color Scale Rule this interface ConditionalFormattingThreshold.RangeType is too unavailable in all POI releases but explained in this link Conditional Formatting Threshold Range Type

Kindly suggest whether these method/interface need to be defined by developers themselves or they are still under apache POI development for future releases?

Any help/suggestions would be highly appreciated. Thanks


回答1:


As detailed in the Apache POI Changelog, the support for Conditional Formatting Colour Scale Rules was added after POI 3.13 beta 1. The first release that will contain it is 3.13 beta 2. (That should be out in a few days, until then you'd need to use a nightly build)

You can find a number of examples of setting up new Color Scale CF rules in the Conditional Formatting unit tests. Taken from there, you'll want something like

Workbook wb = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();

SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
ConditionalFormattingRule rule1 =
            sheetCF.createConditionalFormattingColorScaleRule();
ColorScaleFormatting clrFmt = rule1.getColorScaleFormatting();

clrFmt.getThresholds()[0].setRangeType(RangeType.MIN);
clrFmt.getThresholds()[1].setRangeType(RangeType.NUMBER);
clrFmt.getThresholds()[1].setValue(10d);
clrFmt.getThresholds()[2].setRangeType(RangeType.MAX);

CellRangeAddress [] regions = { CellRangeAddress.valueOf("A1:A5") };
sheetCF.addConditionalFormatting(regions, rule1);


来源:https://stackoverflow.com/questions/32164700/apache-poi-for-xslx-3-color-scale-rule-how-to-define-these-method-createconditi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!