Ajout de formats conditionnels 2 couleurs et 3 couleurs
Contents
[
Hide
]
Les formats conditionnels 2 couleurs et 3 couleurs sont ajoutés de la même manière, sauf qu’ils sont différenciés par la propriété FormatCondition.color_scale.is_3_color_scale. Cette propriété est false pour les formats conditionnels 2 couleurs et true pour les formats conditionnels 3 couleurs.
Le code d’exemple suivant ajoute des formats conditionnels 2 couleurs et 3 couleurs. Il génère le fichier Excel en sortie.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import CellArea, FormatConditionType, Workbook | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook | |
workbook = Workbook() | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Add some data in cells | |
worksheet.cells.get("A1").put_value("2-Color Scale") | |
worksheet.cells.get("D1").put_value("3-Color Scale") | |
for i in range(2, 15 + 1): | |
worksheet.cells.get("A" + str(i)).put_value(i) | |
worksheet.cells.get("D" + str(i)).put_value(i) | |
# Adding 2-Color Scale Conditional Formatting | |
ca = CellArea.create_cell_area("A2", "A15") | |
idx = worksheet.conditional_formattings.add() | |
fcc = worksheet.conditional_formattings[idx] | |
fcc.add_condition(FormatConditionType.COLOR_SCALE) | |
fcc.add_area(ca) | |
fc = worksheet.conditional_formattings[idx][0] | |
fc.color_scale.is_3_color_scale = False | |
fc.color_scale.max_color = Color.light_blue | |
fc.color_scale.min_color = Color.light_green | |
# Adding 3-Color Scale Conditional Formatting | |
ca = CellArea.create_cell_area("D2", "D15") | |
idx = worksheet.conditional_formattings.add() | |
fcc = worksheet.conditional_formattings[idx] | |
fcc.add_condition(FormatConditionType.COLOR_SCALE) | |
fcc.add_area(ca) | |
fc = worksheet.conditional_formattings[idx][0] | |
fc.color_scale.is_3_color_scale = True | |
fc.color_scale.max_color = Color.light_blue | |
fc.color_scale.mid_color = Color.yellow | |
fc.color_scale.min_color = Color.light_green | |
# Save the workbook | |
workbook.save(dataDir + "output_out.xlsx") |