إضافة التدرج اللوني ثنائي اللون والثلاثي اللون وتنسيقهما الشرطي
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook | |
Workbook workbook = new Workbook(); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add some data in cells | |
worksheet.Cells["A1"].PutValue("2-Color Scale"); | |
worksheet.Cells["D1"].PutValue("3-Color Scale"); | |
for (int i = 2; i <= 15; i++) | |
{ | |
worksheet.Cells["A" + i].PutValue(i); | |
worksheet.Cells["D" + i].PutValue(i); | |
} | |
// Adding 2-Color Scale Conditional Formatting | |
CellArea ca = CellArea.CreateCellArea("A2", "A15"); | |
int idx = worksheet.ConditionalFormattings.Add(); | |
FormatConditionCollection fcc = worksheet.ConditionalFormattings[idx]; | |
fcc.AddCondition(FormatConditionType.ColorScale); | |
fcc.AddArea(ca); | |
FormatCondition fc = worksheet.ConditionalFormattings[idx][0]; | |
fc.ColorScale.Is3ColorScale = false; | |
fc.ColorScale.MaxColor = Color.LightBlue; | |
fc.ColorScale.MinColor = Color.LightGreen; | |
// Adding 3-Color Scale Conditional Formatting | |
ca = CellArea.CreateCellArea("D2", "D15"); | |
idx = worksheet.ConditionalFormattings.Add(); | |
fcc = worksheet.ConditionalFormattings[idx]; | |
fcc.AddCondition(FormatConditionType.ColorScale); | |
fcc.AddArea(ca); | |
fc = worksheet.ConditionalFormattings[idx][0]; | |
fc.ColorScale.Is3ColorScale = true; | |
fc.ColorScale.MaxColor = Color.LightBlue; | |
fc.ColorScale.MidColor = Color.Yellow; | |
fc.ColorScale.MinColor = Color.LightGreen; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |