HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
newSheet.addConditionalFormatting(cf);
or to modify existing Conditional Formatting settings (formatting regions and/or rules).
Use org. to get access to an instance of this class.
To create a new Conditional Formatting set use the following approach:
// Define a Conditional Formatting rule, which triggers formatting
// when cell's value is greater or equal than 100.0 and
// applies patternFormatting defined below.
HSSFConditionalFormattingRule rule = sheet.createConditionalFormattingRule(
ComparisonOperator.GE,
"100.0", // 1st formula
null // 2nd formula is not used for comparison operator GE
);
// Create pattern with red background
HSSFPatternFormatting patternFmt = rule.cretePatternFormatting();
patternFormatting.setFillBackgroundColor(HSSFColor.RED.index);
// Define a region containing first column
Region [] regions = {
new Region(1,(short)1,-1,(short)1)
};
// Apply Conditional Formatting rule defined above to the regions
sheet.addConditionalFormatting(regions, rule);
| Modifier and Type | Field and Description |
|---|---|
| private final CFRecordsAggregate | |
| private final HSSFSheet |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | addRule(HSSFConditionalFormattingRule
- Conditional Formatting rule cfRule)add a Conditional Formatting rule. |
| public void | addRule(ConditionalFormattingRule
- Conditional Formatting rule cfRule)Implements org. Add a Conditional Formatting rule. |
| pack-priv CFRecordsAggregate | |
| public CellRangeAddress[] | Returns: array ofCellRangeAddresss. never nullImplements org.
|
| public int | Returns: number of Conditional Formatting rules.Implements org.
|
| public HSSFConditionalFormattingRule | Returns: the Conditional Formatting rule at position idx.Implements org.
|
| public void | setFormattingRanges(final CellRangeAddress[]
non-null array of ranges)CellRangeAddresssImplements org. Sets the cell ranges the rule conditional formatting must be applied to. |
| public void | setRule(int
position of the rule. Should be between 0 and 2 for older Excel versions idx, HSSFConditionalFormattingRule - Conditional Formatting rule cfRule)Replaces an existing Conditional Formatting rule at position idx. |
| public void | setRule(int
position of the rule. Should be between 0 and 2 for Excel before 2007, otherwise 0+. idx, ConditionalFormattingRule - Conditional Formatting rule cfRule)Implements org. Replaces an existing Conditional Formatting rule at position idx. |
| public String |
| cfAggregate | back to summary |
|---|---|
| private final CFRecordsAggregate cfAggregate | |
| sheet | back to summary |
|---|---|
| private final HSSFSheet sheet | |
| HSSFConditionalFormatting | back to summary |
|---|---|
| pack-priv HSSFConditionalFormatting(HSSFSheet sheet, CFRecordsAggregate cfAggregate) | |
| addRule | back to summary |
|---|---|
| public void addRule(HSSFConditionalFormattingRule cfRule) add a Conditional Formatting rule. Excel allows to create up to 3 Conditional Formatting rules.
| |
| addRule | back to summary |
|---|---|
| public void addRule(ConditionalFormattingRule cfRule) Implements org. Doc from org. Add a Conditional Formatting rule. Excel pre-2007 allows to create up to 3 Conditional Formatting rules.
| |
| getCFRecordsAggregate | back to summary |
|---|---|
| pack-priv CFRecordsAggregate getCFRecordsAggregate() | |
| getFormattingRanges | back to summary |
|---|---|
| public CellRangeAddress[] getFormattingRanges() Implements org.
| |
| getNumberOfRules | back to summary |
|---|---|
| public int getNumberOfRules() Implements org.
| |
| getRule | back to summary |
|---|---|
| public HSSFConditionalFormattingRule getRule(int idx) Implements org.
| |
| setFormattingRanges | back to summary |
|---|---|
| public void setFormattingRanges(final CellRangeAddress[] ranges) Implements org. Doc from org. Sets the cell ranges the rule conditional formatting must be applied to.
| |
| setRule | back to summary |
|---|---|
| public void setRule(int idx, HSSFConditionalFormattingRule cfRule) Replaces an existing Conditional Formatting rule at position idx. Older versions of Excel only allow up to 3 Conditional Formatting rules, and will ignore rules beyond that, while newer versions are fine. This method can be useful to modify existing Conditional Formatting rules.
| |
| setRule | back to summary |
|---|---|
| public void setRule(int idx, ConditionalFormattingRule cfRule) Implements org. Doc from org. Replaces an existing Conditional Formatting rule at position idx. Excel pre-2007 allows to create up to 3 Conditional Formatting rules, 2007 and later allow unlimited numbers. This method can be useful to modify existing Conditional Formatting rules.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |