Back to Devexpress

XlCondFmtRuleExpression Class

corelibraries-devexpress-dot-export-dot-xl-634fcf0f.md

latest3.7 KB
Original Source

XlCondFmtRuleExpression Class

Represents the conditional formatting rule that uses a relational operator to determine which cells to format.

Namespace : DevExpress.Export.Xl

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

NuGet Package : DevExpress.Printing.Core

Declaration

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

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 rules should be applied (A2:C7).
formatting.Ranges.Add(XlCellRange.FromLTRB(0, 1, 2, 6));
// Create the rule that uses a formula to highlight cells if a value in the column "C" is greater than 0 and less than 50. 
XlCondFmtRuleExpression rule = new XlCondFmtRuleExpression("AND($C2>0,$C2<50)");
// Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlFill.SolidFill(Color.FromArgb(0xff, 0xff, 0xcc));
formatting.Rules.Add(rule);
// Create the rule that uses a formula to highlight cells if a value in the column "C" is less than or equal to 0. 
rule = new XlCondFmtRuleExpression("$C2<=0");
// 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 rules should be applied (A2:C7).
formatting.Ranges.Add(XlCellRange.FromLTRB(0, 1, 2, 6))
' Create the rule that uses a formula to highlight cells if a value in the column "C" is greater than 0 and less than 50. 
Dim rule As New XlCondFmtRuleExpression("AND($C2>0,$C2<50)")
' Specify formatting settings to be applied to cells if the condition is true.
rule.Formatting = XlFill.SolidFill(Color.FromArgb(&Hff, &Hff, &Hcc))
formatting.Rules.Add(rule)
' Create the rule that uses a formula to highlight cells if a value in the column "C" is less than or equal to 0. 
rule = New XlCondFmtRuleExpression("$C2<=0")
' 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 XlCondFmtRuleExpression

See Also

XlCondFmtRuleExpression Members

DevExpress.Export.Xl Namespace