问题
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