إضافة التدرج اللوني ثنائي اللون والثلاثي اللون وتنسيقهما الشرطي
Contents
[
Hide
]
يتم إضافة التدرج اللوني ثنائي اللون والثلاثي اللون بنفس الطريقة باستثناء أنهم يختلفون بواسطة خاصية FormatCondition.ColorScale.Is3ColorScale . تكون هذه الخاصية false لتدرج اللوني ثنائي اللون و true لتدرج اللوني الثلاثي اللون.
إضافة التدرج اللوني ثنائي اللون والثلاثي اللون
يضم الكود العينة التالي إضافة التدرج اللوني ثنائي وثلاثي اللون. ويولد ملف الإكسل الناتج كما هو موضح أدناه.
This file contains 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
// 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"); |