java.lang.Object
com.aspose.cells.PivotFormatCondition
public class PivotFormatCondition
Example:
Workbook book = new Workbook();
Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();
cells.get(0, 0).setValue("fruit");
cells.get(1, 0).setValue("grape");
cells.get(2, 0).setValue("blueberry");
cells.get(3, 0).setValue("kiwi");
cells.get(4, 0).setValue("cherry");
cells.get(5, 0).setValue("grape");
cells.get(6, 0).setValue("blueberry");
cells.get(7, 0).setValue("kiwi");
cells.get(8, 0).setValue("cherry");
cells.get(0, 1).setValue("year");
cells.get(1, 1).setValue(2020);
cells.get(2, 1).setValue(2020);
cells.get(3, 1).setValue(2020);
cells.get(4, 1).setValue(2020);
cells.get(5, 1).setValue(2021);
cells.get(6, 1).setValue(2021);
cells.get(7, 1).setValue(2021);
cells.get(8, 1).setValue(2021);
cells.get(0, 2).setValue("amount");
cells.get(1, 2).setValue(50);
cells.get(2, 2).setValue(60);
cells.get(3, 2).setValue(70);
cells.get(4, 2).setValue(80);
cells.get(5, 2).setValue(90);
cells.get(6, 2).setValue(100);
cells.get(7, 2).setValue(110);
cells.get(8, 2).setValue(120);
PivotTableCollection pivots = sheet.getPivotTables();
int pivotIndex = pivots.add("=Sheet1!A1:C9", "A12", "TestPivotTable");
PivotTable pivot = pivots.get(pivotIndex);
pivot.addFieldToArea(PivotFieldType.ROW, "fruit");
pivot.addFieldToArea(PivotFieldType.COLUMN, "year");
pivot.addFieldToArea(PivotFieldType.DATA, "amount");
pivot.setPivotTableStyleType(PivotTableStyleType.PIVOT_TABLE_STYLE_MEDIUM_10);
//Add PivotFormatCondition
int formatIndex = pivot.getPivotFormatConditions().add();
PivotFormatCondition pfc = pivot.getPivotFormatConditions().get(formatIndex);
FormatConditionCollection fcc = pfc.getFormatConditions();
fcc.addArea(pivot.getDataBodyRange());
int idx = fcc.addCondition(FormatConditionType.CELL_VALUE);
FormatCondition fc = fcc.get(idx);
fc.setFormula1("100");
fc.setOperator(OperatorType.GREATER_OR_EQUAL);
fc.getStyle().setBackgroundColor(Color.getRed());
pivot.refreshData();
pivot.calculateData();
//do your business
book.save("out.xlsx");
| Property Getters/Setters Summary | ||
|---|---|---|
FormatConditionCollection | getFormatConditions() | |
| Get formatconditions for the pivot table condition format . | ||
int | getRuleType() | |
void | setRuleType(int) | |
| Get and set rule type for the pivot table condition format . The value of the property is PivotConditionFormatRuleType integer constant. | ||
int | getScopeType() | |
void | setScopeType(int) | |
| Get and set scope type for the pivot table condition format . The value of the property is PivotConditionFormatScopeType integer constant. | ||
| Method Summary | ||
|---|---|---|
void | addColumnAreaCondition(PivotField columnField) | |
| Adds PivotTable conditional format limit in the column fields. | ||
void | addColumnAreaCondition(java.lang.String fieldName) | |
| Adds PivotTable conditional format limit in the column fields. | ||
void | addDataAreaCondition(PivotField dataField) | |
| Adds PivotTable conditional format limit in the data fields. | ||
void | addDataAreaCondition(java.lang.String fieldName) | |
| Adds PivotTable conditional format limit in the data fields. | ||
void | addRowAreaCondition(PivotField rowField) | |
| Adds PivotTable conditional format limit in the row fields. | ||
void | addRowAreaCondition(java.lang.String fieldName) | |
| Adds PivotTable conditional format limit in the row fields. | ||
void | setConditionalAreas() | |
| Sets conditional areas of PivotFormatCondition object. | ||
| Property Getters/Setters Detail |
|---|
getScopeType/setScopeType | |
public int getScopeType() / public void setScopeType(int value) | |
getRuleType/setRuleType | |
public int getRuleType() / public void setRuleType(int value) | |
getFormatConditions | |
public FormatConditionCollection getFormatConditions() | |
| Method Detail |
|---|
addDataAreaCondition | |
public void addDataAreaCondition(java.lang.String fieldName) | |
fieldName - The name of PivotField.addDataAreaCondition | |
public void addDataAreaCondition(PivotField dataField) | |
dataField - The PivotField in the data fields.addRowAreaCondition | |
public void addRowAreaCondition(java.lang.String fieldName) | |
fieldName - The name of PivotField.addRowAreaCondition | |
public void addRowAreaCondition(PivotField rowField) | |
rowField - The PivotField in the row fields.addColumnAreaCondition | |
public void addColumnAreaCondition(java.lang.String fieldName) | |
fieldName - The name of PivotField.addColumnAreaCondition | |
public void addColumnAreaCondition(PivotField columnField) | |
columnField - The PivotField in the column fields.setConditionalAreas | |
public void setConditionalAreas()
throws java.lang.Exception | |