Example usage for org.apache.poi.ss.usermodel ConditionalFormattingRule getConditionType

List of usage examples for org.apache.poi.ss.usermodel ConditionalFormattingRule getConditionType

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel ConditionalFormattingRule getConditionType.

Prototype

ConditionType getConditionType();

Source Link

Document

Type of conditional formatting rule.

Usage

From source file:com.vaadin.addon.spreadsheet.ConditionalFormatter.java

/**
 * Checks if the given cell value matches the given conditional formatting
 * rule.// ww  w .  ja v  a2 s  .com
 *
 * @param cell
 *            Target cell
 * @param rule
 *            Conditional formatting rule to check against
 * @return Whether the given rule evaluates to <code>true</code> for the
 *         given cell.
 */
protected boolean matches(Cell cell, ConditionalFormattingRule rule, int deltaColumn, int deltaRow) {
    /*
     * Formula type is the default for most rules in modern excel files.
     * 
     * There are a couple of issues with this.
     * 
     * 1. the condition type seems to be '0' in all xlsx files, which is an
     * illegal value according to the API. The formula is still correct, and
     * can be accessed.
     * 
     * 2. in xls-files the type is correct, but the formula is not: it
     * references the wrong cell.
     * 
     * 3. the formula is a String. POIs FormulaEvaluation only takes Cell
     * arguments. So, to use it, we need to copy the formula to an existing
     * cell temporarily, and run the eval.
     */
    if (rule.getConditionType().equals(ConditionType.CELL_VALUE_IS)) {
        return matchesValue(cell, rule);
    } else {
        return matchesFormula(rule, deltaColumn, deltaRow);
    }

}

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());//from w w  w  .ja  v a  2  s  . c om
    } 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();
}