Hinzufügen von bedingten Formates mit 2 Farbskala und 3 Farbskala
Contents
[
Hide
]
2-Farbmuster und 3-Farbmuster Bedingte Formatierungen werden auf die gleiche Weise hinzugefügt, außer dass sie sich durch die FormatCondition.color_scale.is_3_color_scale-Eigenschaft unterscheiden. Diese Eigenschaft ist falsch für 2-Farbmuster und wahr für 3-Farbmuster Bedingte Formatierungen.
Der folgende Beispielcode fügt 2-Farbmuster und 3-Farbmuster Bedingte Formatierungen hinzu. Es generiert die Ausgabedatei Excel.
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") |