protected void formatCellStatus(Sheet sheet, Cell cell) { cell.setCellStyle(styles.get("status")); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); ConditionalFormattingRule ruleGreen = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "1"); PatternFormatting fill1 = ruleGreen.createPatternFormatting(); fill1.setFillBackgroundColor(IndexedColors.GREEN.index); fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND); // ConditionalFormattingRule ruleRed = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "0"); PatternFormatting fill2 = ruleRed.createPatternFormatting(); fill2.setFillBackgroundColor(IndexedColors.RED.index); fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND); // ConditionalFormattingRule ruleOrange = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "2"); PatternFormatting fill3 = ruleOrange.createPatternFormatting(); fill3.setFillBackgroundColor(IndexedColors.ORANGE.index); fill3.setFillPattern(PatternFormatting.SOLID_FOREGROUND); // String name = CellReference.convertNumToColString(cell.getColumnIndex()); String location = "$" + name + "$" + cell.getRowIndex() + ":$" + name + "$" + (cell.getRowIndex() + 1); CellRangeAddress[] regions = { CellRangeAddress.valueOf(location) }; ConditionalFormattingRule[] cfRules = new ConditionalFormattingRule[] { ruleGreen, ruleRed, ruleOrange }; sheetCF.addConditionalFormatting(regions, cfRules); }
public SheetConditionalFormatting getSheetConditionalFormatting() { return sheet.getSheetConditionalFormatting(); }
/** * Not supported */ @Override public SheetConditionalFormatting getSheetConditionalFormatting() { throw new UnsupportedOperationException(); }