List of usage examples for org.apache.poi.ss.usermodel ConditionalFormattingRule getMultiStateFormatting
IconMultiStateFormatting getMultiStateFormatting();
From source file:de.jlo.talendcomp.excel.SpreadsheetOutput.java
License:Apache License
private static String describeRule(ConditionalFormattingRule rule) { StringBuilder sb = new StringBuilder(); sb.append("condition:"); ConditionType ct = rule.getConditionType(); if (ct.equals(ConditionType.CELL_VALUE_IS)) { sb.append(" cell value is: "); sb.append(describeRuleComparisonOperator(rule)); } else if (ct.equals(ConditionType.FORMULA)) { sb.append(" formula: "); sb.append(rule.getFormula1());/* w ww .java2s. co m*/ } else if (ct.equals(ConditionType.FILTER)) { sb.append(" filter: "); sb.append(describeRuleComparisonOperator(rule)); } else if (ct.equals(ConditionType.ICON_SET)) { sb.append(" icon set: "); sb.append(rule.getMultiStateFormatting()); } else if (ct.equals(ConditionType.COLOR_SCALE)) { sb.append(" color-scale: "); sb.append(rule.getColorScaleFormatting()); } else if (ct.equals(ConditionType.DATA_BAR)) { sb.append(" data-bar: "); sb.append(rule.getDataBarFormatting()); } else { sb.append(" type=" + rule.getConditionType()); } sb.append(" formattings:"); if (rule.getBorderFormatting() != null) { sb.append(" [has border formats]"); } if (rule.getFontFormatting() != null) { sb.append(" [has font formattings]"); } if (rule.getPatternFormatting() != null) { sb.append(" [has pattern formattings]"); } return sb.toString(); }
From source file:packtest.ConditionalFormats.java
License:Apache License
/** * Icon Sets / Multi-States allow you to have icons shown which vary * based on the values, eg Red traffic light / Yellow traffic light / * Green traffic light//from w w w . ja v a2s. co m */ static void iconSets(Sheet sheet) { sheet.createRow(0).createCell(0).setCellValue("Icon Sets"); Row r = sheet.createRow(1); r.createCell(0).setCellValue("Reds"); r.createCell(1).setCellValue(0); r.createCell(2).setCellValue(0); r.createCell(3).setCellValue(0); r = sheet.createRow(2); r.createCell(0).setCellValue("Yellows"); r.createCell(1).setCellValue(5); r.createCell(2).setCellValue(5); r.createCell(3).setCellValue(5); r = sheet.createRow(3); r.createCell(0).setCellValue("Greens"); r.createCell(1).setCellValue(10); r.createCell(2).setCellValue(10); r.createCell(3).setCellValue(10); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); CellRangeAddress[] regions = { CellRangeAddress.valueOf("B1:B4") }; ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(IconSet.GYR_3_TRAFFIC_LIGHTS); IconMultiStateFormatting im1 = rule1.getMultiStateFormatting(); im1.getThresholds()[0].setRangeType(RangeType.MIN); im1.getThresholds()[1].setRangeType(RangeType.PERCENT); im1.getThresholds()[1].setValue(33d); im1.getThresholds()[2].setRangeType(RangeType.MAX); sheetCF.addConditionalFormatting(regions, rule1); regions = new CellRangeAddress[] { CellRangeAddress.valueOf("C1:C4") }; ConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(IconSet.GYR_3_FLAGS); IconMultiStateFormatting im2 = rule1.getMultiStateFormatting(); im2.getThresholds()[0].setRangeType(RangeType.PERCENT); im2.getThresholds()[0].setValue(0d); im2.getThresholds()[1].setRangeType(RangeType.PERCENT); im2.getThresholds()[1].setValue(33d); im2.getThresholds()[2].setRangeType(RangeType.PERCENT); im2.getThresholds()[2].setValue(67d); sheetCF.addConditionalFormatting(regions, rule2); regions = new CellRangeAddress[] { CellRangeAddress.valueOf("D1:D4") }; ConditionalFormattingRule rule3 = sheetCF.createConditionalFormattingRule(IconSet.GYR_3_SYMBOLS_CIRCLE); IconMultiStateFormatting im3 = rule1.getMultiStateFormatting(); im3.setIconOnly(true); im3.getThresholds()[0].setRangeType(RangeType.MIN); im3.getThresholds()[1].setRangeType(RangeType.NUMBER); im3.getThresholds()[1].setValue(3d); im3.getThresholds()[2].setRangeType(RangeType.NUMBER); im3.getThresholds()[2].setValue(7d); sheetCF.addConditionalFormatting(regions, rule3); }