FormatCondition

Inheritance: java.lang.Object

public class FormatCondition

Represents conditional formatting condition.

Example

         //Instantiating a Workbook object
         Workbook workbook = new Workbook();
         Worksheet sheet = workbook.getWorksheets().get(0);
 
         //Adds an empty conditional formatting
         int index = sheet.getConditionalFormattings().add();
         FormatConditionCollection fcs = sheet.getConditionalFormattings().get(index);
 
         //Sets the conditional format range.
         CellArea ca = new CellArea();
         ca.StartRow = 0;
         ca.EndRow = 0;
         ca.StartColumn = 0;
         ca.EndColumn = 0;
         fcs.addArea(ca);
 
         ca = new CellArea();
         ca.StartRow = 1;
         ca.EndRow = 1;
         ca.StartColumn = 1;
         ca.EndColumn = 1;
         fcs.addArea(ca);
 
         //Adds condition.
         int conditionIndex = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "=A2", "100");
 
         //Adds condition.
         int conditionIndex2 = fcs.addCondition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100");
 
         //Sets the background color.
         FormatCondition fc = fcs.get(conditionIndex);
         fc.getStyle().setBackgroundColor(Color.getRed());
 
         //Saving the Excel file
         workbook.save("output.xls");

Methods

MethodDescription
equals(Object arg0)
getAboveAverage()Get the conditional formatting’s “AboveAverage” instance.
getClass()
getColorScale()Get the conditional formatting’s “ColorScale” instance.
getDataBar()Get the conditional formatting’s “DataBar” instance.
getFormula1()Gets the value or expression associated with conditional formatting.
getFormula1(boolean isR1C1, boolean isLocal)Gets the value or expression associated with this format condition.
getFormula1(boolean isR1C1, boolean isLocal, int row, int column)Gets the value or expression of the conditional formatting of the cell.
getFormula1(int row, int column)Gets the formula of the conditional formatting of the cell.
getFormula2()Gets the value or expression associated with conditional formatting.
getFormula2(boolean isR1C1, boolean isLocal)Gets the value or expression associated with this format condition.
getFormula2(boolean isR1C1, boolean isLocal, int row, int column)Gets the value or expression of the conditional formatting of the cell.
getFormula2(int row, int column)Gets the formula of the conditional formatting of the cell.
getIconSet()Get the conditional formatting’s “IconSet” instance.
getOperator()Gets the conditional format operator type.
getPriority()The priority of this conditional formatting rule.
getStopIfTrue()True, no rules with lower priority may be applied over this rule, when this rule evaluates to true.
getStyle()Gets or setts style of conditional formatted cell ranges.
getText()The text value in a “text contains” conditional formatting rule.
getTimePeriod()The applicable time period in a “date occurring\u9225?
getTop10()Get the conditional formatting’s “Top10” instance.
getType()Gets whether the conditional format Type.
hashCode()
notify()
notifyAll()
setFormula1(String value)Sets the value or expression associated with conditional formatting.
setFormula1(String formula, boolean isR1C1, boolean isLocal)Sets the value or expression associated with this format condition.
setFormula2(String value)Sets the value or expression associated with conditional formatting.
setFormula2(String formula, boolean isR1C1, boolean isLocal)Sets the value or expression associated with this format condition.
setFormulas(String formula1, String formula2, boolean isR1C1, boolean isLocal)Sets the value or expression associated with this format condition.
setOperator(int value)Sets the conditional format operator type.
setPriority(int value)The priority of this conditional formatting rule.
setStopIfTrue(boolean value)True, no rules with lower priority may be applied over this rule, when this rule evaluates to true.
setStyle(Style value)Gets or setts style of conditional formatted cell ranges.
setText(String value)The text value in a “text contains” conditional formatting rule.
setTimePeriod(int value)The applicable time period in a “date occurring\u9225?
setType(int value)Sets whether the conditional format Type.
toString()
wait()
wait(long arg0)
wait(long arg0, int arg1)

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

getAboveAverage()

public AboveAverage getAboveAverage()

Get the conditional formatting’s “AboveAverage” instance. The default instance’s rule highlights cells that are above the average for all values in the range. Valid only for type = AboveAverage.

Returns: AboveAverage -

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getColorScale()

public ColorScale getColorScale()

Get the conditional formatting’s “ColorScale” instance. The default instance is a “green-yellow-red” 3ColorScale . Valid only for type = ColorScale.

Returns: ColorScale -

getDataBar()

public DataBar getDataBar()

Get the conditional formatting’s “DataBar” instance. The default instance’s color is blue. Valid only for type is DataBar.

Returns: DataBar -

getFormula1()

public String getFormula1()

Gets the value or expression associated with conditional formatting.

Remarks

Please add all areas before setting formula. For setting formula for this condition, if the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “=\"=…\””.

Returns: java.lang.String

getFormula1(boolean isR1C1, boolean isLocal)

public String getFormula1(boolean isR1C1, boolean isLocal)

Gets the value or expression associated with this format condition.

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.

Returns: java.lang.String - The value or expression associated with this format condition.

getFormula1(boolean isR1C1, boolean isLocal, int row, int column)

public String getFormula1(boolean isR1C1, boolean isLocal, int row, int column)

Gets the value or expression of the conditional formatting of the cell.

Remarks

The given cell must be contained by this conditional formatting, otherwise null will be returned.

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.
rowintThe row index.
columnintThe column index.

Returns: java.lang.String - The value or expression associated with the conditional formatting of the cell.

getFormula1(int row, int column)

public String getFormula1(int row, int column)

Gets the formula of the conditional formatting of the cell.

Parameters:

ParameterTypeDescription
rowintThe row index.
columnintThe column index.

Returns: java.lang.String - The formula.

getFormula2()

public String getFormula2()

Gets the value or expression associated with conditional formatting.

Remarks

Please add all areas before setting formula. For setting formula for this condition, if the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “=\"=…\””.

Returns: java.lang.String

getFormula2(boolean isR1C1, boolean isLocal)

public String getFormula2(boolean isR1C1, boolean isLocal)

Gets the value or expression associated with this format condition.

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.

Returns: java.lang.String - The value or expression associated with this format condition.

getFormula2(boolean isR1C1, boolean isLocal, int row, int column)

public String getFormula2(boolean isR1C1, boolean isLocal, int row, int column)

Gets the value or expression of the conditional formatting of the cell.

Remarks

The given cell must be contained by this conditional formatting, otherwise null will be returned.

Parameters:

ParameterTypeDescription
isR1C1booleanWhether the formula needs to be formatted as R1C1.
isLocalbooleanWhether the formula needs to be formatted by locale.
rowintThe row index.
columnintThe column index.

Returns: java.lang.String - The value or expression associated with the conditional formatting of the cell.

getFormula2(int row, int column)

public String getFormula2(int row, int column)

Gets the formula of the conditional formatting of the cell.

Parameters:

ParameterTypeDescription
rowintThe row index.
columnintThe column index.

Returns: java.lang.String - The formula.

getIconSet()

public IconSet getIconSet()

Get the conditional formatting’s “IconSet” instance. The default instance’s IconSetType is TrafficLights31. Valid only for type = IconSet.

Returns: IconSet -

getOperator()

public int getOperator()

Gets the conditional format operator type.

See OperatorType.

Returns: int

getPriority()

public int getPriority()

The priority of this conditional formatting rule. This value is used to determine which format should be evaluated and rendered. Lower numeric values are higher priority than higher numeric values, where ‘1’ is the highest priority.

Returns: int

getStopIfTrue()

public boolean getStopIfTrue()

True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;

Returns: boolean

getStyle()

public Style getStyle()

Gets or setts style of conditional formatted cell ranges.

Returns: Style

getText()

public String getText()

The text value in a “text contains” conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null.

Returns: java.lang.String

getTimePeriod()

public int getTimePeriod()

The applicable time period in a “date occurring\u9225? conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.

See TimePeriodType.

Returns: int

getTop10()

public Top10 getTop10()

Get the conditional formatting’s “Top10” instance. The default instance’s rule highlights cells whose values fall in the top 10 bracket. Valid only for type is Top10.

Returns: Top10 -

getType()

public int getType()

Gets whether the conditional format Type.

See FormatConditionType.

Returns: int

hashCode()

public native int hashCode()

Returns: int

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

setFormula1(String value)

public void setFormula1(String value)

Sets the value or expression associated with conditional formatting.

Remarks

Please add all areas before setting formula. For setting formula for this condition, if the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “=\"=…\””.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setFormula1(String formula, boolean isR1C1, boolean isLocal)

public void setFormula1(String formula, boolean isR1C1, boolean isLocal)

Sets the value or expression associated with this format condition.

Parameters:

ParameterTypeDescription
formulajava.lang.StringThe value or expression associated with this format condition. If the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “=\"=…\”".
isR1C1booleanWhether the formula is R1C1 formula.
isLocalbooleanWhether the formula is locale formatted.

setFormula2(String value)

public void setFormula2(String value)

Sets the value or expression associated with conditional formatting.

Remarks

Please add all areas before setting formula. For setting formula for this condition, if the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “=\"=…\”".

Parameters:

ParameterTypeDescription
valuejava.lang.String

setFormula2(String formula, boolean isR1C1, boolean isLocal)

public void setFormula2(String formula, boolean isR1C1, boolean isLocal)

Sets the value or expression associated with this format condition.

Parameters:

ParameterTypeDescription
formulajava.lang.StringThe value or expression associated with this format condition. If the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “=\"=…\”".
isR1C1booleanWhether the formula is R1C1 formula.
isLocalbooleanWhether the formula is locale formatted.

setFormulas(String formula1, String formula2, boolean isR1C1, boolean isLocal)

public void setFormulas(String formula1, String formula2, boolean isR1C1, boolean isLocal)

Sets the value or expression associated with this format condition.

Parameters:

ParameterTypeDescription
formula1java.lang.StringThe value or expression associated with this format condition. If the input value starts with ‘=’, then it will be taken as formula. Otherwise it will be taken as plain value(text, number, bool). For text value that starts with ‘=’, user may input it as formula in format: “=\"=…\”".
formula2java.lang.StringThe value or expression associated with this format condition. The input format is same with formula1
isR1C1booleanWhether the formula is R1C1 formula.
isLocalbooleanWhether the formula is locale formatted.

setOperator(int value)

public void setOperator(int value)

Sets the conditional format operator type.

See OperatorType.

Parameters:

ParameterTypeDescription
valueint

setPriority(int value)

public void setPriority(int value)

The priority of this conditional formatting rule. This value is used to determine which format should be evaluated and rendered. Lower numeric values are higher priority than higher numeric values, where ‘1’ is the highest priority.

Parameters:

ParameterTypeDescription
valueint

setStopIfTrue(boolean value)

public void setStopIfTrue(boolean value)

True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007;

Parameters:

ParameterTypeDescription
valueboolean

setStyle(Style value)

public void setStyle(Style value)

Gets or setts style of conditional formatted cell ranges.

Parameters:

ParameterTypeDescription
valueStyle

setText(String value)

public void setText(String value)

The text value in a “text contains” conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setTimePeriod(int value)

public void setTimePeriod(int value)

The applicable time period in a “date occurring\u9225? conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today.

See TimePeriodType.

Parameters:

ParameterTypeDescription
valueint

setType(int value)

public void setType(int value)

Sets whether the conditional format Type.

See FormatConditionType.

Parameters:

ParameterTypeDescription
valueint

toString()

public String toString()

Returns: java.lang.String

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int