Ajout de formats conditionnels 2 couleurs et 3 couleurs

Ajout de mises en forme conditionnelles à 2 couleurs et à 3 couleurs

Le code d’exemple suivant ajoute des mises en forme conditionnelles à 2 niveaux et à 3 niveaux. Il génère le fichier Excel de sortie comme indiqué ci-dessous.

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getDataDir(AddingTwoAndThreeColorScale.class);
// Create workbook
Workbook workbook = new Workbook();
// Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Add some data in cells
worksheet.getCells().get("A1").putValue("2-Color Scale");
worksheet.getCells().get("D1").putValue("3-Color Scale");
for (int i = 2; i <= 15; i++) {
worksheet.getCells().get("A" + i).putValue(i);
worksheet.getCells().get("D" + i).putValue(i);
}
// Adding 2-Color Scale Conditional Formatting
CellArea ca = CellArea.createCellArea("A2", "A15");
int idx = worksheet.getConditionalFormattings().add();
FormatConditionCollection fcc = worksheet.getConditionalFormattings().get(idx);
fcc.addCondition(FormatConditionType.COLOR_SCALE);
fcc.addArea(ca);
FormatCondition fc = worksheet.getConditionalFormattings().get(idx).get(0);
fc.getColorScale().setIs3ColorScale(false);
fc.getColorScale().setMaxColor(Color.getLightBlue());
fc.getColorScale().setMinColor(Color.getLightGreen());
// Adding 3-Color Scale Conditional Formatting
ca = CellArea.createCellArea("D2", "D15");
idx = worksheet.getConditionalFormattings().add();
fcc = worksheet.getConditionalFormattings().get(idx);
fcc.addCondition(FormatConditionType.COLOR_SCALE);
fcc.addArea(ca);
fc = worksheet.getConditionalFormattings().get(idx).get(0);
fc.getColorScale().setIs3ColorScale(true);
fc.getColorScale().setMaxColor(Color.getLightBlue());
fc.getColorScale().setMidColor(Color.getYellow());
fc.getColorScale().setMinColor(Color.getLightGreen());
// Save the workbook
workbook.save(dataDir + "output.xlsx");