Back to Devexpress

XlCondFmtRuleAboveAverage Class

corelibraries-devexpress-dot-export-dot-xl-6ce2baff.md

latest7.4 KB
Original Source

XlCondFmtRuleAboveAverage Class

Represents the “Above or Below Average…” conditional formatting rule.

Namespace : DevExpress.Export.Xl

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public class XlCondFmtRuleAboveAverage :
    XlCondFmtRuleWithFormatting
vb
Public Class XlCondFmtRuleAboveAverage
    Inherits XlCondFmtRuleWithFormatting

Remarks

The conditional formatting rule, represented by the XlCondFmtRuleAboveAverage object, formats cells whose values are above or below the average for all values in the range.

Example

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

csharp
// Create an instance of the XlConditionalFormatting class.
XlConditionalFormatting formatting = new XlConditionalFormatting();
// Specify the cell range to which the conditional formatting rule should be applied (A1:A11).
formatting.Ranges.Add(XlCellRange.FromLTRB(0, 0, 0, 10));
// Create the rule highlighting values that are above the average in the cell range.
XlCondFmtRuleAboveAverage rule = new XlCondFmtRuleAboveAverage();
rule.Condition = XlCondFmtAverageCondition.Above;
// Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Good;
formatting.Rules.Add(rule);
// Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting);

// Create an instance of the XlConditionalFormatting class.
formatting = new XlConditionalFormatting();
// Specify the cell range to which the conditional formatting rule should be applied (B1:B11).
formatting.Ranges.Add(XlCellRange.FromLTRB(1, 0, 1, 10));
// Create the rule highlighting values that are above or equal to the average value in the cell range.
rule = new XlCondFmtRuleAboveAverage();
rule.Condition = XlCondFmtAverageCondition.AboveOrEqual;
// Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Good;
formatting.Rules.Add(rule);
// Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting);

// Create an instance of the XlConditionalFormatting class.
formatting = new XlConditionalFormatting();
// Specify the cell range to which the conditional formatting rule should be applied (C1:C11).
formatting.Ranges.Add(XlCellRange.FromLTRB(2, 0, 2, 10));
// Create the rule highlighting values that are below the average in the cell range.
rule = new XlCondFmtRuleAboveAverage();
rule.Condition = XlCondFmtAverageCondition.Below;
// Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Bad;
formatting.Rules.Add(rule);
// Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting);

// Create an instance of the XlConditionalFormatting class.
formatting = new XlConditionalFormatting();
// Specify the cell range to which the conditional formatting rule should be applied (D1:D11).
formatting.Ranges.Add(XlCellRange.FromLTRB(3, 0, 3, 10));
// Create the rule highlighting values that are below or equal to the average value in the cell range.
rule = new XlCondFmtRuleAboveAverage();
rule.Condition = XlCondFmtAverageCondition.BelowOrEqual;
// Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Bad;
formatting.Rules.Add(rule);
// Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting);
vb
' Create an instance of the XlConditionalFormatting class.
Dim formatting As New XlConditionalFormatting()
' Specify the cell range to which the conditional formatting rule should be applied (A1:A11).
formatting.Ranges.Add(XlCellRange.FromLTRB(0, 0, 0, 10))
' Create the rule highlighting values that are above the average in the cell range.
Dim rule As New XlCondFmtRuleAboveAverage()
rule.Condition = XlCondFmtAverageCondition.Above
' Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Good
formatting.Rules.Add(rule)
' Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting)

' Create an instance of the XlConditionalFormatting class.
formatting = New XlConditionalFormatting()
' Specify the cell range to which the conditional formatting rule should be applied (B1:B11).
formatting.Ranges.Add(XlCellRange.FromLTRB(1, 0, 1, 10))
' Create the rule highlighting values that are above or equal to the average value in the cell range.
rule = New XlCondFmtRuleAboveAverage()
rule.Condition = XlCondFmtAverageCondition.AboveOrEqual
' Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Good
formatting.Rules.Add(rule)
' Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting)

' Create an instance of the XlConditionalFormatting class.
formatting = New XlConditionalFormatting()
' Specify the cell range to which the conditional formatting rule should be applied (C1:C11).
formatting.Ranges.Add(XlCellRange.FromLTRB(2, 0, 2, 10))
' Create the rule highlighting values that are below the average in the cell range.
rule = New XlCondFmtRuleAboveAverage()
rule.Condition = XlCondFmtAverageCondition.Below
' Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Bad
formatting.Rules.Add(rule)
' Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting)

' Create an instance of the XlConditionalFormatting class.
formatting = New XlConditionalFormatting()
' Specify the cell range to which the conditional formatting rule should be applied (D1:D11).
formatting.Ranges.Add(XlCellRange.FromLTRB(3, 0, 3, 10))
' Create the rule highlighting values that are below or equal to the average value in the cell range.
rule = New XlCondFmtRuleAboveAverage()
rule.Condition = XlCondFmtAverageCondition.BelowOrEqual
' Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlCellFormatting.Bad
formatting.Rules.Add(rule)
' Add the specified format options to the worksheet collection of conditional formats.
sheet.ConditionalFormattings.Add(formatting)

Inheritance

Object XlCondFmtRule XlCondFmtRuleWithFormatting XlCondFmtRuleAboveAverage

See Also

XlCondFmtRuleAboveAverage Members

DevExpress.Export.Xl Namespace