FormatConditionCollection

Inheritance: java.lang.Object

public class FormatConditionCollection

Represents conditional formatting. The FormatConditions can contain up to three conditional formats.

Example

         //Create a new Workbook.
         Workbook workbook = new Workbook();
 
         //Get the first worksheet.
         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
add(CellArea cellArea, int type, int operatorType, String formula1, String formula2)Adds a formatting condition and effected cell rang to the FormatConditions The FormatConditions can contain up to three conditional formats.
addArea(CellArea cellArea)Adds a conditional formatted cell range.
addCondition(int type)Add a format condition.
addCondition(int type, int operatorType, String formula1, String formula2)Adds a formatting condition.
equals(Object arg0)
get(int index)Gets the formatting condition by index.
getCellArea(int index)Gets the conditional formatted cell range by index.
getClass()
getCount()Gets the count of the conditions.
getRangeCount()Gets count of conditionally formatted ranges.
hashCode()
notify()
notifyAll()
removeArea(int index)Removes conditional formatted cell range by index.
removeArea(int startRow, int startColumn, int totalRows, int totalColumns)Remove conditional formatting int the range.
removeCondition(int index)Removes the formatting condition by index.
toString()
wait()
wait(long arg0)
wait(long arg0, int arg1)

add(CellArea cellArea, int type, int operatorType, String formula1, String formula2)

public int[] add(CellArea cellArea, int type, int operatorType, String formula1, String formula2)

Adds a formatting condition and effected cell rang to the FormatConditions The FormatConditions can contain up to three conditional formats. References to the other sheets are not allowed in the formulas of conditional formatting.

Parameters:

ParameterTypeDescription
cellAreaCellAreaConditional formatted cell range.
typeintFormatConditionType. Type of conditional formatting.It could be one of the members of FormatConditionType.
operatorTypeintOperatorType. Comparison operator.It could be one of the members of OperatorType.
formula1java.lang.StringThe value or expression associated with conditional formatting.
formula2java.lang.StringThe value or expression associated with conditional formatting

Returns: int[] - [0]:Formatting condition object index;[1] Effected cell rang index.

addArea(CellArea cellArea)

public int addArea(CellArea cellArea)

Adds a conditional formatted cell range.

Parameters:

ParameterTypeDescription
cellAreaCellAreaConditional formatted cell range.

Returns: int - Conditional formatted cell rang index.

addCondition(int type)

public int addCondition(int type)

Add a format condition.

Parameters:

ParameterTypeDescription
typeintFormatConditionType. Format condition type.

Returns: int - Formatting condition object index;

addCondition(int type, int operatorType, String formula1, String formula2)

public int addCondition(int type, int operatorType, String formula1, String formula2)

Adds a formatting condition.

Parameters:

ParameterTypeDescription
typeintFormatConditionType. The type of format condition.
operatorTypeintOperatorType. The operator type
formula1java.lang.StringThe value or expression associated with conditional formatting. 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 conditional formatting. The input format is same with formula1

Returns: int - Formatting condition object index;

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

get(int index)

public FormatCondition get(int index)

Gets the formatting condition by index.

Parameters:

ParameterTypeDescription
indexintthe index of the formatting condition to return.

Returns: FormatCondition - the formatting condition

getCellArea(int index)

public CellArea getCellArea(int index)

Gets the conditional formatted cell range by index.

Parameters:

ParameterTypeDescription
indexintthe index of the conditional formatted cell range.

Returns: CellArea - the conditional formatted cell range

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getCount()

public int getCount()

Gets the count of the conditions.

Returns: int

getRangeCount()

public int getRangeCount()

Gets count of conditionally formatted ranges.

Returns: int

hashCode()

public native int hashCode()

Returns: int

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

removeArea(int index)

public void removeArea(int index)

Removes conditional formatted cell range by index.

Parameters:

ParameterTypeDescription
indexintThe index of the conditional formatted cell range to be removed.

removeArea(int startRow, int startColumn, int totalRows, int totalColumns)

public boolean removeArea(int startRow, int startColumn, int totalRows, int totalColumns)

Remove conditional formatting int the range.

Parameters:

ParameterTypeDescription
startRowintThe startRow of the range.
startColumnintThe startColumn of the range.
totalRowsintThe number of rows of the range.
totalColumnsintThe number of columns of the range.

Returns: boolean - Returns TRUE, this FormatCondtionCollection should be removed.

removeCondition(int index)

public void removeCondition(int index)

Removes the formatting condition by index.

Parameters:

ParameterTypeDescription
indexintThe index of the formatting condition to be removed.

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