Top Description Methods
org.apache.poi.ss.usermodel

public Interface SheetConditionalFormatting

Known Direct Implementers
org.apache.poi.hssf.usermodel.HSSFSheetConditionalFormatting
Imports
org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet, org.apache.poi.ss.util.CellRangeAddress

The 'Conditional Formatting' facet of Sheet
Since
3.8

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

index of the newly created Conditional Formatting object
addConditionalFormatting
(CellRangeAddress[]
- list of rectangular regions to apply conditional formatting rules
regions
,
ConditionalFormattingRule
- the rule to apply
rule
)

Add a new Conditional Formatting to the sheet.

public int

Returns:

index of the newly created Conditional Formatting object
addConditionalFormatting
(CellRangeAddress[]
- list of rectangular regions to apply conditional formatting rules
regions
,
ConditionalFormattingRule
- the first rule
rule1
,
ConditionalFormattingRule
- the second rule
rule2
)

Add a new Conditional Formatting consisting of two rules.

public int

Returns:

index of the newly created Conditional Formatting object
addConditionalFormatting
(CellRangeAddress[]
- list of rectangular regions to apply conditional formatting rules
regions
,
ConditionalFormattingRule[]
- set of up to conditional formatting rules (max 3 for Excel pre-2007)
cfRules
)

Add a new Conditional Formatting set to the sheet.

public int

Returns:

index of the new Conditional Formatting object
addConditionalFormatting
(ConditionalFormatting
the Conditional Formatting to clone
cf
)

Adds a copy of a ConditionalFormatting object to the sheet

This method could be used to copy ConditionalFormatting object from one sheet to another.

public ConditionalFormattingRule
createConditionalFormattingColorScaleRule()

Create a Color Scale / Color Gradient conditional formatting rule.

public ConditionalFormattingRule
createConditionalFormattingRule(byte
- MUST be a constant value from ComparisonOperator:
  • BETWEEN
  • NOT_BETWEEN
  • EQUAL
  • NOT_EQUAL
  • GT
  • LT
  • GE
  • LE
comparisonOperation
,
String
- formula for the valued, compared with the cell
formula1
,
String
- second formula (only used with ComparisonOperator#BETWEEN) and ComparisonOperator#NOT_BETWEEN operations)
formula2
)

A factory method allowing to create a conditional formatting rule with a cell comparison operator

The created conditional formatting rule compares a cell value to a formula calculated result, using the specified operator.

public ConditionalFormattingRule
createConditionalFormattingRule(byte
MUST be a constant value from ComparisonOperator except BETWEEN and NOT_BETWEEN
comparisonOperation
,
String
the formula to determine if the conditional formatting is applied
formula
)

Create a conditional formatting rule that compares a cell value to a formula calculated result, using an operator *

The type of the created condition is ConditionType#CELL_VALUE_IS

public ConditionalFormattingRule
createConditionalFormattingRule(String
the formula to evaluate. MUST be a Boolean function.
formula
)

Create a conditional formatting rule based on a Boolean formula.

public ConditionalFormattingRule
createConditionalFormattingRule(ExtendedColor color)

Create a Databar conditional formatting rule.

public ConditionalFormattingRule
createConditionalFormattingRule(IconMultiStateFormatting.IconSet iconSet)

Create an Icon Set / Multi-State conditional formatting rule.

public ConditionalFormatting

Returns:

Conditional Formatting object or null if not found
getConditionalFormattingAt
(int
0-based index of the Conditional Formatting object to fetch
index
)

Gets Conditional Formatting object at a particular index

public int

Returns:

the number of conditional formats in this sheet
getNumConditionalFormattings
()

public void
removeConditionalFormatting(int
0-based index of the Conditional Formatting object to remove
index
)

Removes a Conditional Formatting object by index

Method Detail

addConditionalFormattingback to summary
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule rule)

Add a new Conditional Formatting to the sheet.

Parameters
regions:CellRangeAddress[]

- list of rectangular regions to apply conditional formatting rules

rule:ConditionalFormattingRule

- the rule to apply

Returns:int

index of the newly created Conditional Formatting object

addConditionalFormattingback to summary
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule rule1, ConditionalFormattingRule rule2)

Add a new Conditional Formatting consisting of two rules.

Parameters
regions:CellRangeAddress[]

- list of rectangular regions to apply conditional formatting rules

rule1:ConditionalFormattingRule

- the first rule

rule2:ConditionalFormattingRule

- the second rule

Returns:int

index of the newly created Conditional Formatting object

addConditionalFormattingback to summary
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules)

Add a new Conditional Formatting set to the sheet.

Parameters
regions:CellRangeAddress[]

- list of rectangular regions to apply conditional formatting rules

cfRules:ConditionalFormattingRule[]

- set of up to conditional formatting rules (max 3 for Excel pre-2007)

Returns:int

index of the newly created Conditional Formatting object

addConditionalFormattingback to summary
public int addConditionalFormatting(ConditionalFormatting cf)

Adds a copy of a ConditionalFormatting object to the sheet

This method could be used to copy ConditionalFormatting object from one sheet to another. For example:

ConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
newSheet.addConditionalFormatting(cf);
Parameters
cf:ConditionalFormatting

the Conditional Formatting to clone

Returns:int

index of the new Conditional Formatting object

createConditionalFormattingColorScaleRuleback to summary
public ConditionalFormattingRule createConditionalFormattingColorScaleRule()

Create a Color Scale / Color Gradient conditional formatting rule.

The thresholds and colours for it will be created, but will be empty and require configuring with ConditionalFormattingRule#getColorScaleFormatting() then ColorScaleFormatting#getThresholds() and ColorScaleFormatting#getColors()

createConditionalFormattingRuleback to summary
public ConditionalFormattingRule createConditionalFormattingRule(byte comparisonOperation, String formula1, String formula2)

A factory method allowing to create a conditional formatting rule with a cell comparison operator

The created conditional formatting rule compares a cell value to a formula calculated result, using the specified operator. The type of the created condition is ConditionType#CELL_VALUE_IS

Parameters
comparisonOperation:byte

- MUST be a constant value from ComparisonOperator:

  • BETWEEN
  • NOT_BETWEEN
  • EQUAL
  • NOT_EQUAL
  • GT
  • LT
  • GE
  • LE
formula1:String

- formula for the valued, compared with the cell

formula2:String

- second formula (only used with ComparisonOperator#BETWEEN) and ComparisonOperator#NOT_BETWEEN operations)

createConditionalFormattingRuleback to summary
public ConditionalFormattingRule createConditionalFormattingRule(byte comparisonOperation, String formula)

Create a conditional formatting rule that compares a cell value to a formula calculated result, using an operator *

The type of the created condition is ConditionType#CELL_VALUE_IS

Parameters
comparisonOperation:byte

MUST be a constant value from ComparisonOperator except BETWEEN and NOT_BETWEEN

formula:String

the formula to determine if the conditional formatting is applied

createConditionalFormattingRuleback to summary
public ConditionalFormattingRule createConditionalFormattingRule(String formula)

Create a conditional formatting rule based on a Boolean formula. When the formula result is true, the cell is highlighted.

The type of the created format condition is ConditionType#FORMULA

Parameters
formula:String

the formula to evaluate. MUST be a Boolean function.

createConditionalFormattingRuleback to summary
public ConditionalFormattingRule createConditionalFormattingRule(ExtendedColor color)

Create a Databar conditional formatting rule.

The thresholds and colour for it will be created, but will be empty and require configuring with ConditionalFormattingRule#getDataBarFormatting() then DataBarFormatting#getMinThreshold() and DataBarFormatting#getMaxThreshold()

createConditionalFormattingRuleback to summary
public ConditionalFormattingRule createConditionalFormattingRule(IconMultiStateFormatting.IconSet iconSet)

Create an Icon Set / Multi-State conditional formatting rule.

The thresholds for it will be created, but will be empty and require configuring with ConditionalFormattingRule#getMultiStateFormatting() then IconMultiStateFormatting#getThresholds()

getConditionalFormattingAtback to summary
public ConditionalFormatting getConditionalFormattingAt(int index)

Gets Conditional Formatting object at a particular index

Parameters
index:int

0-based index of the Conditional Formatting object to fetch

Returns:ConditionalFormatting

Conditional Formatting object or null if not found

Exceptions
IllegalArgumentException:
if the index is outside of the allowable range (0 ... numberOfFormats-1)
getNumConditionalFormattingsback to summary
public int getNumConditionalFormattings()
Returns:int

the number of conditional formats in this sheet

removeConditionalFormattingback to summary
public void removeConditionalFormatting(int index)

Removes a Conditional Formatting object by index

Parameters
index:int

0-based index of the Conditional Formatting object to remove

Exceptions
IllegalArgumentException:
if the index is outside of the allowable range (0 ... numberOfFormats-1)