كيفية إضافة تنسيق شرطي لأعلى 10
سيناريوهات الاستخدام المحتملة
يساعد استخدام التنسيق الشرطي Top10 في إكسل على إبراز قيم الأداء الأعلى بسرعة في مجموعة البيانات — ليس فقط أعلى 10 قيم حرفيًا، ولكن غالبًا أعلى N قيم أو أعلى N% (يمكنك الاختيار!).
- اكتشاف الاتجاهات والقيم الشاذة: حدد بسرعة الأفضل أداءً (على سبيل المثال، أفضل 10 مندوبي مبيعات، أفضل المعدلات، أشهر الأرباح). يسهل التحليل دون ترتيب البيانات.
- تصور البيانات: يضيف تلميحات لون تجعل نقاط البيانات المهمة تبرز بصريًا. يساعد مشاهدين جدول البيانات على فهم القيم الرئيسية بنظرة سريعة.
- مقارنات سريعة: مفيد في لوحات المعلومات والتقارير حيث تريد إبراز التميز أو القمم.
- تحديثات ديناميكية: إذا تغيرت بياناتك، يتحدث التنسيق الشرطي تلقائيًا ليعكس القيم الأعلى الجديدة.
كيفية إضافة التنسيق الشرطي Top10 باستخدام Excel
إليك كيفية إضافة التنسيق الشرطي Top10 في Excel، خطوة بخطوة:
- حدد نطاق الخلايا الذي تريد تحليله. على سبيل المثال: حدد B2:B100، إذا كنت تعمل مع الدرجات أو أرقام المبيعات.
- اذهب إلى علامة التبويب الصفحة الرئيسية في شريط أدوات Excel.
- انقر على التنسيق الشرطي في مجموعة الأنماط.
- مرر فوق قواعد القمة / القاع في القائمة المنسدلة.
- انقر على أعلى 10 عناصر…
- ستظهر نافذة حوار: ستقول: تنسيق الخلايا التي تتصدر الترتيب في أعلى 10. يمكنك تغيير الرقم (مثلاً، أعلى 5، أعلى 3، إلخ.). اختر تنسيقًا (مثل تعبئة خفيفة حمرا، نص عريض، أو انقر على تنسيق مخصص لمزيد من الخيارات).
- انقر على موافق.
كيفية إضافة التنسيق الشرطي Top10 باستخدام Aspose.Cells for .NET
يدعم Aspose.Cells تمامًا التنسيق الشرطي المقدم بواسطة مايكروسوفت إكسل 2007 والإصدارات الأحدث بصيغة XLSX على الخلايا في وقت التشغيل. يُظهر هذا المثال تمرينًا للتنسيق الشرطي Top 10 مع مجموعات مختلفة من الصفات.
private void TestTop10() | |
{ | |
// Instantiate a workbook object | |
Workbook book = new Workbook(); | |
// Create a worksheet object and get the first worksheet | |
Worksheet _sheet = book.Worksheets[0]; | |
AddTop10_1(_sheet); | |
AddTop10_2(_sheet); | |
AddTop10_3(_sheet); | |
AddTop10_4(_sheet); | |
book.Save(filePath + "Top10.xlsx"); | |
} | |
// This method implements a simple Top10 conditional formatting type. | |
private void AddTop10_1(Worksheet _sheet) | |
{ | |
FormatConditionCollection conds = GetFormatCondition("A17:C20", Color.Gray, _sheet); | |
int idx = conds.AddCondition(FormatConditionType.Top10); | |
FormatCondition cond = conds[idx]; | |
cond.Style.BackgroundColor = Color.Yellow; | |
cond.Style.Pattern = BackgroundType.Solid; | |
} | |
// This method implements another Top10 conditional formatting type. | |
private void AddTop10_2(Worksheet _sheet) | |
{ | |
FormatConditionCollection conds = GetFormatCondition("A21:C24", Color.Green, _sheet); | |
int idx = conds.AddCondition(FormatConditionType.Top10); | |
FormatCondition cond = conds[idx]; | |
cond.Style.BackgroundColor = Color.Pink; | |
cond.Style.Pattern = BackgroundType.Solid; | |
cond.Top10.IsBottom = true; | |
} | |
// This method implements another Top10 conditional formatting type with some custom attributes. | |
private void AddTop10_3(Worksheet _sheet) | |
{ | |
FormatConditionCollection conds = GetFormatCondition("A25:C28", Color.Orange, _sheet); | |
int idx = conds.AddCondition(FormatConditionType.Top10); | |
FormatCondition cond = conds[idx]; | |
cond.Style.BackgroundColor = Color.Blue; | |
cond.Style.Pattern = BackgroundType.Solid; | |
cond.Top10.IsPercent = true; | |
} | |
// This method implements another Top10 conditional formatting type with some custom attributes. | |
private void AddTop10_4(Worksheet _sheet) | |
{ | |
FormatConditionCollection conds = GetFormatCondition("A29:C32", Color.Gold, _sheet); | |
int idx = conds.AddCondition(FormatConditionType.Top10); | |
FormatCondition cond = conds[idx]; | |
cond.Style.BackgroundColor = Color.Green; | |
cond.Style.Pattern = BackgroundType.Solid; | |
cond.Top10.Rank = 3; | |
} | |
// This method adds formatted conditions. | |
private FormatConditionCollection GetFormatCondition(string cellAreaName, Color color, Worksheet _sheet) | |
{ | |
// Adds an empty conditional formattings | |
int index = _sheet.ConditionalFormattings.Add(); | |
// Get the formatted conditions | |
FormatConditionCollection formatConditions = _sheet.ConditionalFormattings[index]; | |
// Get the cell area calling the custom GetCellAreaByName method | |
CellArea area = GetCellAreaByName(cellAreaName); | |
// Add the formatted conditions cell area. | |
formatConditions.AddArea(area); | |
// Call the custom FillCell method | |
FillCell(cellAreaName, color, _sheet); | |
// Return the formatted conditions | |
return formatConditions; | |
} | |
// This method specifies the cell shading color for the conditional formattings cellarea range. | |
private void FillCell(string cellAreaName, Color color, Worksheet _sheet) | |
{ | |
CellArea area = GetCellAreaByName(cellAreaName); | |
int k = 0; | |
for (int i = area.StartColumn; i <= area.EndColumn; i++) | |
{ | |
for (int j = area.StartRow; j <= area.EndRow; j++) | |
{ | |
Cell c = _sheet.Cells[j, i]; | |
if (!color.IsEmpty) | |
{ | |
Style s = c.GetStyle(); | |
s.ForegroundColor = color; | |
s.Pattern = BackgroundType.Solid; | |
c.SetStyle(s); | |
} | |
// Set some random values to the cells in the cellarea range | |
int value = j + i + k; | |
c.PutValue(value); | |
k++; | |
} | |
} | |
} | |
// This method specifies the CellArea range (start row, start col, end row, end col etc.) | |
// For the conditional formatting | |
internal static CellArea GetCellAreaByName(string s) | |
{ | |
CellArea area = new CellArea(); | |
string[] strCellRange = s.Replace("$", "").Split(':'); | |
int column; | |
CellsHelper.CellNameToIndex(strCellRange[0], out area.StartRow, out column); | |
area.StartColumn = column; | |
if (strCellRange.Length == 1) | |
{ | |
area.EndRow = area.StartRow; | |
area.EndColumn = area.StartColumn; | |
} | |
else | |
{ | |
CellsHelper.CellNameToIndex(strCellRange[1], out area.EndRow, out column); | |
area.EndColumn = column; | |
} | |
return area; | |
} |