public class FormatCondition
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("C:\\output.xls");
Property Getters/Setters Summary | ||
---|---|---|
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.
|
||
ColorScale | getColorScale() | |
Get the conditional formatting's "ColorScale" instance.
The default instance is a "green-yellow-red" 3ColorScale .
Valid only for type = ColorScale.
|
||
DataBar | getDataBar() | |
Get the conditional formatting's "DataBar" instance.
The default instance's color is blue.
Valid only for type is DataBar.
|
||
java.lang.String | getFormula1() | |
void | setFormula1(java.lang.Stringvalue) | |
Gets and sets the value or expression associated with conditional formatting. | ||
java.lang.String | getFormula2() | |
void | setFormula2(java.lang.Stringvalue) | |
Gets and sets the value or expression associated with conditional formatting. | ||
IconSet | getIconSet() | |
Get the conditional formatting's "IconSet" instance.
The default instance's IconSetType is TrafficLights31.
Valid only for type = IconSet.
|
||
int | getOperator() | |
void | setOperator(intvalue) | |
Gets and sets the conditional format operator type. The value of the property is OperatorType integer constant. | ||
int | getPriority() | |
void | setPriority(intvalue) | |
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. | ||
boolean | getStopIfTrue() | |
void | setStopIfTrue(booleanvalue) | |
True, no rules with lower priority may be applied over this rule, when this rule evaluates to true. Only applies for Excel 2007; | ||
Style | getStyle() | |
void | ||
Gets or setts style of conditional formatted cell ranges. | ||
java.lang.String | getText() | |
void | setText(java.lang.Stringvalue) | |
The text value in a "text contains" conditional formatting rule. Valid only for type = containsText, notContainsText, beginsWith and endsWith. The default value is null. | ||
int | getTimePeriod() | |
void | setTimePeriod(intvalue) | |
The applicable time period in a "date occurring¡" conditional formatting rule. Valid only for type = timePeriod. The default value is TimePeriodType.Today. The value of the property is TimePeriodType integer constant. | ||
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.
|
||
int | getType() | |
void | setType(intvalue) | |
Gets and sets whether the conditional format Type. The value of the property is FormatConditionType integer constant. |
Method Summary | ||
---|---|---|
java.lang.String | getFormula1(boolean isR1C1, boolean isLocal) | |
Gets the value or expression associated with this format condition.
|
||
java.lang.String | getFormula1(boolean isR1C1, boolean isLocal, int row, int column) | |
Gets the value or expression of the conditional formatting of the cell.
|
||
java.lang.String | getFormula1(int row, int column) | |
Gets the formula of the conditional formatting of the cell.
|
||
java.lang.String | getFormula2(boolean isR1C1, boolean isLocal) | |
Gets the value or expression associated with this format condition.
|
||
java.lang.String | getFormula2(boolean isR1C1, boolean isLocal, int row, int column) | |
Gets the value or expression of the conditional formatting of the cell.
|
||
java.lang.String | getFormula2(int row, int column) | |
Gets the formula of the conditional formatting of the cell.
|
||
void | setFormula1(java.lang.String formula, boolean isR1C1, boolean isLocal) | |
Sets the value or expression associated with this format condition.
|
||
void | setFormula2(java.lang.String formula, boolean isR1C1, boolean isLocal) | |
Sets the value or expression associated with this format condition.
|
||
void | setFormulas(java.lang.String formula1, java.lang.String formula2, boolean isR1C1, boolean isLocal) | |
Sets the value or expression associated with this format condition.
|
public java.lang.String getFormula1() / public void setFormula1(java.lang.String value)
public java.lang.String getFormula2() / public void setFormula2(java.lang.String value)
public int getOperator() / public void setOperator(int value)
public boolean getStopIfTrue() / public void setStopIfTrue(boolean value)
public int getPriority() / public void setPriority(int value)
public Style getStyle() / public void setStyle(Style value)
public int getType() / public void setType(int value)
public IconSet getIconSet()
public DataBar getDataBar()
public ColorScale getColorScale()
public Top10 getTop10()
public AboveAverage getAboveAverage()
public java.lang.String getText() / public void setText(java.lang.String value)
public int getTimePeriod() / public void setTimePeriod(int value)
public java.lang.String getFormula1(boolean isR1C1, boolean isLocal)
isR1C1
- Whether the formula needs to be formatted as R1C1.isLocal
- Whether the formula needs to be formatted by locale.public java.lang.String getFormula2(boolean isR1C1, boolean isLocal)
isR1C1
- Whether the formula needs to be formatted as R1C1.isLocal
- Whether the formula needs to be formatted by locale.public java.lang.String getFormula1(boolean isR1C1, boolean isLocal, int row, int column)
isR1C1
- Whether the formula needs to be formatted as R1C1.isLocal
- Whether the formula needs to be formatted by locale.row
- The row index.column
- The column index.public java.lang.String getFormula2(boolean isR1C1, boolean isLocal, int row, int column)
isR1C1
- Whether the formula needs to be formatted as R1C1.isLocal
- Whether the formula needs to be formatted by locale.row
- The row index.column
- The column index.public void setFormulas(java.lang.String formula1, java.lang.String formula2, boolean isR1C1, boolean isLocal)
formula1
- The 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: "=\"=...\"".formula2
- The value or expression associated with this format condition. The input format is same with formula1isR1C1
- Whether the formula is R1C1 formula.isLocal
- Whether the formula is locale formatted.public void setFormula1(java.lang.String formula, boolean isR1C1, boolean isLocal)
formula
- The 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: "=\"=...\"".isR1C1
- Whether the formula is R1C1 formula.isLocal
- Whether the formula is locale formatted.public void setFormula2(java.lang.String formula, boolean isR1C1, boolean isLocal)
formula
- The 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: "=\"=...\"".isR1C1
- Whether the formula is R1C1 formula.isLocal
- Whether the formula is locale formatted.public java.lang.String getFormula1(int row, int column)
row
- The row index.column
- The column index.public java.lang.String getFormula2(int row, int column)
row
- The row index.column
- The column index.