Back to Devexpress

ConditionalFormattingCollection.AddTimePeriodConditionalFormatting(CellRange, ConditionalFormattingTimePeriod) Method

officefileapi-devexpress-dot-spreadsheet-dot-conditionalformattingcollection-dot-addtimeperiodconditionalformatting-x28-devexpress-dot-spreadsheet-dot-cellrange-devexpress-dot-spreadsheet-dot-conditionalformattingtimeperiod-x29.md

latest9.9 KB
Original Source

ConditionalFormattingCollection.AddTimePeriodConditionalFormatting(CellRange, ConditionalFormattingTimePeriod) Method

Applies a "date occurring…" conditional formatting rule.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
TimePeriodConditionalFormatting AddTimePeriodConditionalFormatting(
    CellRange range,
    ConditionalFormattingTimePeriod timePeriod
)
vb
Function AddTimePeriodConditionalFormatting(
    range As CellRange,
    timePeriod As ConditionalFormattingTimePeriod
) As TimePeriodConditionalFormatting

Parameters

NameTypeDescription
rangeCellRange

A CellRange object that specifies a range of cells to which the conditional formatting rule is applied.

| | timePeriod | ConditionalFormattingTimePeriod |

One of the ConditionalFormattingTimePeriod enumeration values specifying time periods to be highlighted in a range of cells.

|

Returns

TypeDescription
TimePeriodConditionalFormatting

A TimePeriodConditionalFormatting object that represents the specified conditional format.

|

Example

This example demonstrates how to apply a "date occurring…" conditional formatting rule.

  1. To create a new conditional formatting rule represented by the TimePeriodConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddTimePeriodConditionalFormatting method. Pass the following parameters:

  2. Specify formatting options to be applied to cells if the condition is true using the ISupportsFormatting.Formatting property of the TimePeriodConditionalFormatting object.

Note

Transparency is not supported in conditional formatting.

To remove the TimePeriodConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.

View Example

csharp
// Create the rule to highlight today's dates in cells B2 through B6.
TimePeriodConditionalFormatting cfRule =
worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet.Range["$B$2:$B$6"], ConditionalFormattingTimePeriod.Today);
// Specify formatting options to be applied to cells if the condition is true.
// Set the background color to pink.
cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xF2, 0xAE, 0xE3);
vb
' Create the rule to highlight today's dates in cells B2 through B6.
Dim cfRule As TimePeriodConditionalFormatting = worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet.Range("$B$2:$B$6"), ConditionalFormattingTimePeriod.Today)
' Specify formatting options to be applied to cells if the condition is true.
' Set the background color to pink.
cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, &HF2, &HAE, &HE3)

The following code snippets (auto-collected from DevExpress Examples) contain references to the AddTimePeriodConditionalFormatting(CellRange, ConditionalFormattingTimePeriod) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

spreadsheet-document-api-apply-conditional-formatting-to-cell-range/CS/ConditionalFormatting_Example/SpreadsheetActions/ConditionalFormatting.cs#L183

csharp
TimePeriodConditionalFormatting cfRule =
worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet["$B$2:$B$6"], ConditionalFormattingTimePeriod.Today);
// Specify formatting options to be applied to cells if the condition is true.

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/CS/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.cs#L181

csharp
TimePeriodConditionalFormatting cfRule =
worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet.Range["$B$2:$B$6"], ConditionalFormattingTimePeriod.Today);
// Specify formatting options to be applied to cells if the condition is true.

wpf-spreadsheet-how-to-apply-conditional-formatting-to-a-range-of-cells/CS/ConditionalFormatting_WPF_Examples/SpreadsheetActions/ConditionalFormatting.cs#L180

csharp
TimePeriodConditionalFormatting cfRule =
worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet.Range["$B$2:$B$6"], ConditionalFormattingTimePeriod.Today);
// Specify formatting options to be applied to cells if the condition is true.

spreadsheet-document-api-apply-conditional-formatting-to-cell-range/VB/ConditionalFormatting_Example/SpreadsheetActions/ConditionalFormatting.vb#L165

vb
' Create the rule to highlight today's dates in cells B2 through B6.
Dim cfRule As TimePeriodConditionalFormatting = worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet("$B$2:$B$6"), ConditionalFormattingTimePeriod.Today)
' Specify formatting options to be applied to cells if the condition is true.

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/VB/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.vb#L159

vb
' Create the rule to highlight today's dates in cells B2 through B6.
Dim cfRule As TimePeriodConditionalFormatting = worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet.Range("$B$2:$B$6"), ConditionalFormattingTimePeriod.Today)
' Specify formatting options to be applied to cells if the condition is true.

wpf-spreadsheet-how-to-apply-conditional-formatting-to-a-range-of-cells/VB/ConditionalFormatting_WPF_Examples/SpreadsheetActions/ConditionalFormatting.vb#L157

vb
' Create the rule to highlight today's dates in cells B2 through B6.
Dim cfRule As TimePeriodConditionalFormatting = worksheet.ConditionalFormattings.AddTimePeriodConditionalFormatting(worksheet.Range("$B$2:$B$6"), ConditionalFormattingTimePeriod.Today)
' Specify formatting options to be applied to cells if the condition is true.

See Also

ConditionalFormattingCollection Interface

ConditionalFormattingCollection Members

DevExpress.Spreadsheet Namespace