كيفية إضافة تنسيق شرطي فوق المتوسط

سيناريوهات الاستخدام المحتملة

استخدام التنسيق الشرطي فوق المتوسط في أدوات مثل Microsoft Excel أو Google Sheets هو وسيلة سريعة ومرئية لتسليط الضوء على البيانات التي تبرز — بالتحديد القيم الأعلى من المتوسط في نطاق معين. إليك الأسباب التي قد تدفعك لاستخدامه:

  1. اكتشاف الاتجاهات بسرعة: يساعدك على تحديد القيم عالية الأداء على الفور دون حساب المتوسطات يدويًا أو فحص الأرقام.
  2. تبسيط تحليل البيانات: لا تحتاج إلى حساب أو إدخال أي صيغ — إنها طريقة تلقائية لتطبيق التنسيق القائم على المنطق، مما يوفر الوقت.
  3. تحسين الجاذبية البصرية: يساعد الترميز بالألوان على جعل جدول البيانات أسهل في القراءة وأكثر جاذبية بصريًا، خاصة أثناء العروض التقديمية.
  4. دعم اتخاذ القرار: تحديد القيم فوق المتوسط بسرعة يمكن أن يدفع إلى إجراءات، مثل مكافأة الم.Lowperformers أو التحقيق في سبب تفوق بعض المنتجات على الأخرى.

كيفية إضافة التنسيق الشرطي فوق المتوسط باستخدام إكسل

لإضافة التنسيق الشرطي فوق المتوسط في إكسل، إليك الخطوة خطوة:

  1. حدد نطاق الخلايا التي تريد تطبيق التنسيق عليها. على سبيل المثال: A1:A20.
  2. انتقل إلى علامة التبويب الصفحة الرئيسية على الشريط.
  3. انقر على التنسيق الشرطي في مجموعة الأنماط.
  4. مرر فوق قواعد العلو/السفل.
  5. انقر فوق فوق المتوسط…
  6. في مربع الحوار الذي يظهر: سوف يكتشف تلقائيًا “تنسق الخلايا التي فوق المتوسط.” يمكنك تغيير نمط التنسيق بالنقر على السهم المنسدل بجانب (على سبيل المثال، اختيار تعبئة لون أو تنسيق مخصص).
  7. انقر على موافق. ستتم إبراز جميع الخلايا في النطاق الذي حددته والتي تفوق متوسط هذا النطاق.

كيفية إضافة تنسيق شرطي فوق المتوسط باستخدام Aspose.Cells for .NET

تدعم Aspose.Cells بالكامل التنسيق الشرطي المقدم من قبل مايكروسوفت إكسل 2007 والإصدارات الأحدث في صيغة XLSX على خلايا عند التشغيل. يوضح هذا المثال تمرين للتنسيق الشرطي فوق المتوسط مع مجموعات مختلفة من السمات.

private void TestAboveAverage()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
AddAboveAverage(_sheet);
AddAboveAverage2(_sheet);
AddAboveAverage3(_sheet);
book.Save(filePath + "AboveAverage.xlsx");
}
// This method implements the AboveAverage conditional formatting type.
private void AddAboveAverage(Worksheet _sheet)
{
FormatConditionCollection conds = GetFormatCondition("A11:C12", Color.Tomato, _sheet);
int idx = conds.AddCondition(FormatConditionType.AboveAverage);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
}
// This method implements an AboveAverage conditional formatting type with some custom attributes.
private void AddAboveAverage2(Worksheet _sheet)
{
FormatConditionCollection conds = GetFormatCondition("A13:C14", Color.Empty, _sheet);
int idx = conds.AddCondition(FormatConditionType.AboveAverage);
FormatCondition cond = conds[idx];
cond.AboveAverage.IsAboveAverage = false;
cond.AboveAverage.IsEqualAverage = true;
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
}
// This method implements an AboveAverage conditional formatting type with some custom attributes.
private void AddAboveAverage3(Worksheet _sheet)
{
FormatConditionCollection conds = GetFormatCondition("A15:C16", Color.Empty, _sheet);
int idx = conds.AddCondition(FormatConditionType.AboveAverage);
FormatCondition cond = conds[idx];
cond.AboveAverage.IsAboveAverage = false;
cond.AboveAverage.IsEqualAverage = true;
cond.AboveAverage.StdDev = 3;
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
}
// 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;
}