Class CellFormattingEventArgs
Provides data for the CellFormatting event, raised before a cell style or number format is applied.
Inherited Members
Namespace: Syncfusion.Blazor.Spreadsheet
Assembly: Syncfusion.Blazor.Spreadsheet.dll
Syntax
public class CellFormattingEventArgs
Remarks
This class contains details about the formatting operation, including the target range, formatting type, current formatting information of the target cell or range, and a flag to cancel the operation.
The event is raised before the formatting is applied, allowing to inspect the operation and cancel it if needed.
Use this event to enforce validation rules or restrict formatting.
Examples
This example demonstrates how to handle the CellFormatting event to inspect the current formatting of the target cell or range and cancel the operation when a condition is met.
<SfSpreadsheet CellFormatting="OnCellFormatting">
<SpreadsheetRibbon></SpreadsheetRibbon>
</SfSpreadsheet>
@code {
private void OnCellFormatting(CellFormattingEventArgs args)
{
// Prevent formatting changes for cells with a red background
if (args.Format != null && args.Format.BackgroundColor == "#FF0000")
{
args.Cancel = true;
}
}
}
Constructors
CellFormattingEventArgs()
Declaration
public CellFormattingEventArgs()
Properties
Cancel
Gets or sets a value indicating whether the formatting operation should be cancelled.
Declaration
public bool Cancel { get; set; }
Property Value
| Type | Description |
|---|---|
| bool | A bool indicating whether to cancel the formatting operation. The default value is |
Remarks
When set to true, the cell style or number format will not be applied to the worksheet.
This property allows event handlers to prevent the default formatting behavior based on validation rules or user permissions.
Format
Gets the formatting details of the target cell or range.
Declaration
public CellStyle Format { get; }
Property Value
| Type | Description |
|---|---|
| CellStyle | A CellStyle object containing the current formatting information of the selected cell or range. |
Remarks
This property contains the current formatting details of the target cell or range prior to the formatting operation.
Use this property to inspect the existing formatting state before applying new style or number format changes.
FormatType
Gets the type of formatting being applied.
Declaration
public string FormatType { get; }
Property Value
| Type | Description |
|---|---|
| string | A string indicating the formatting type. Supported values are |
Remarks
Use this property to determine whether a cell style or a number format is being applied and to execute custom logic accordingly.
NumberFormat
Gets the current number format of the target cell or range.
Declaration
public string NumberFormat { get; }
Property Value
| Type | Description |
|---|---|
| string | A string representing the existing number format pattern of the selected cell or range. The default value is null. |
Remarks
This property provides the current number format of the target cell or range before the formatting operation is processed.
Range
Gets the A1-style range address that the formatting operation will be applied to.
Declaration
public string Range { get; }
Property Value
| Type | Description |
|---|---|
| string | A string in A1 notation (for example, "A1:D10"). The default value is |
Remarks
This property identifies the target cell or range for the formatting operation.