Skip to content

Commit edd3a3d

Browse files
996176: Added UG content for completed features , API and events.
1 parent 434706d commit edd3a3d

File tree

9 files changed

+400
-39
lines changed

9 files changed

+400
-39
lines changed

Document-Processing-toc.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5111,6 +5111,7 @@
51115111
<li><a href="/document-processing/excel/spreadsheet/blazor/cell-range">Cell Range</a></li>
51125112
<li><a href="/document-processing/excel/spreadsheet/blazor/editing">Editing</a></li>
51135113
<li><a href="/document-processing/excel/spreadsheet/blazor/formulas">Formulas</a></li>
5114+
<li><a href="/document-processing/excel/spreadsheet/blazor/formatting">Formatting></li>
51145115
<li><a href="/document-processing/excel/spreadsheet/blazor/contextmenu">Context Menu</a></li>
51155116
<li><a href="/document-processing/excel/spreadsheet/blazor/rows-and-columns">Rows and Columns</a></li>
51165117
<li><a href="/document-processing/excel/spreadsheet/blazor/filtering">Filtering</a></li>

Document-Processing/Excel/Spreadsheet/Blazor/cell-range.md

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,6 @@ documentation: ug
1010
# Managing Cell Ranges in Blazor Spreadsheet component
1111
A cell range is a set of selected cells in a Spreadsheet, typically specified using A1 notation (for example, `A1:B10`). A range may be a single cell or a contiguous block of cells that can be manipulated or processed collectively.
1212

13-
## Cell formatting
14-
15-
Cell formatting enhances the visual presentation of data by applying styles such as font changes, colors, borders, and alignment to individual cells or cell ranges. This helps organize content and emphasize important information for faster interpretation.
16-
17-
Cell formatting options include:
18-
19-
* **Bold** - Applies a heavier font weight to make the text stand out in the Spreadsheet.
20-
21-
* **Italic** - Slants the text to give it a distinct look, often used for emphasis or to highlight differences.
22-
23-
* **Underline** - Adds a line below the text, commonly used for emphasis or to indicate hyperlinks.
24-
25-
* **Strikethrough** - Draws a line through the text, often used to show completed tasks or outdated information.
26-
27-
* **Font Family** - Changes the typeface of the text (e.g., Arial, Calibri, Times New Roman, and more) to enhance readability or visual appeal.
28-
29-
* **Font Size** - Adjusts the size of the text to create visual hierarchy or improve readability in the Spreadsheet.
30-
31-
* **Font Color** - Changes the color of the text to improve visual hierarchy or to organize information using color codes.
32-
33-
* **Fill Color** - Adds color to the cell background to visually organize data or highlight important information.
34-
35-
* **Horizontal Alignment** - Controls the position of text from left to right within a cell. Options include:
36-
* **Left** - Default for text
37-
* **Center** - Useful for headings
38-
* **Right** - Default for numbers
39-
40-
* **Vertical Alignment** - Controls the position of text from top to bottom within a cell. Options include:
41-
* **Top** – Aligns content to the top of the cell
42-
* **Middle** – Centers content vertically
43-
* **Bottom** – Default alignment
44-
45-
* **Wrap Text** - Displays long content on multiple lines within a single cell, preventing it from overflowing into adjacent cells. To enable text wrapping:
46-
1. Select the target cell or range (e.g., C5).
47-
2. Go to the Home tab.
48-
3. Click Wrap Text in the ribbon to toggle text wrapping for the selected cells.
49-
50-
Cell formatting can be applied or removed from a cell or range by using the options available in the component's built-in **Ribbon** under the **Home** tab.
51-
5213
## Autofill
5314

5415
Autofill is used to fill cells with data that follows a pattern or is based on data in other cells. It helps avoid entering repetitive data manually. The [AllowAutofill](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AllowAutofill) property can be used to enable or disable this feature.

Document-Processing/Excel/Spreadsheet/Blazor/editing.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,105 @@ To exit edit mode without saving changes, press the **ESCAPE** key. This action
8484

8585
![Animation showing a user canceling a cell edit in the Blazor Spreadsheet component.](./images/cell-editing.gif)
8686

87+
## Events
88+
89+
The Blazor Spreadsheet provides events that are triggered during editing operations, such as [CellEditing](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.CellEditingEventArgs.html) and [CellSaved](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.CellSavedEventArgs.html). These events enable the execution of custom actions before and after a cell edit, allowing for validation, customization, and response handling.
90+
91+
### CellEditing
92+
93+
The `CellEditing` event is triggered before a cell enters edit mode, allowing for validation or cancellation of the edit operation.
94+
95+
**Purpose**
96+
97+
This event is useful for scenarios where cell editing needs to be controlled dynamically, such as restricting editing in specific ranges or preventing editing based on certain conditions.
98+
99+
**Event Arguments**
100+
101+
The event uses the [CellEditingEventArgs](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.CellEditingEventArgs.html) class, which includes the following properties:
102+
103+
| Event Arguments | Description |
104+
|---|---|
105+
| RowIndex | The zero-based row index of the cell being edited. |
106+
| ColIndex | The zero-based column index of the cell being edited. |
107+
| Address | The address of the cell being edited (e.g., "A1"). |
108+
| Value | The current value of the cell before editing. |
109+
| Cancel | Set to `true` to cancel the editing operation. |
110+
111+
{% tabs %}
112+
{% highlight razor tabtitle="Index.razor" %}
113+
114+
@using Syncfusion.Blazor.Spreadsheet
115+
116+
<SfSpreadsheet DataSource="DataSourceBytes" CellEditing="OnCellEditing">
117+
<SpreadsheetRibbon></SpreadsheetRibbon>
118+
</SfSpreadsheet>
119+
120+
@code {
121+
public byte[] DataSourceBytes { get; set; }
122+
123+
protected override void OnInitialized()
124+
{
125+
string filePath = "wwwroot/Sample.xlsx";
126+
DataSourceBytes = File.ReadAllBytes(filePath);
127+
}
128+
129+
private void OnCellEditing(CellEditingEventArgs args)
130+
{
131+
// Prevents editing in the first row.
132+
if (args.RowIndex == 0)
133+
{
134+
args.Cancel = true;
135+
}
136+
}
137+
}
138+
{% endhighlight %}
139+
{% endtabs %}
140+
141+
### CellSaved
142+
143+
The `CellSaved` event is raised after a cell's value has been successfully saved, providing details about the change and the action that triggered it.
144+
145+
**Purpose**
146+
147+
This event is useful for scenarios where post-editing actions are needed, such as logging the cell change, updating related data, or triggering additional UI updates.
148+
149+
**Event Arguments**
150+
151+
The event uses the [CellSavedEventArgs](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.CellSavedEventArgs.html) class, which includes the following properties:
152+
153+
| Event Arguments | Description |
154+
|---|---|
155+
| Address | The address of the cell whose value was saved (e.g., "A1"). |
156+
| Value | The new value of the cell after saving. |
157+
| OldValue | The original value of the cell before saving. |
158+
| Action | The action that triggered the save (e.g., "Edit", "Cut", "Paste", "Autofill"). |
159+
160+
{% tabs %}
161+
{% highlight razor tabtitle="Index.razor" %}
162+
163+
@using Syncfusion.Blazor.Spreadsheet
164+
165+
<SfSpreadsheet DataSource="DataSourceBytes" CellSaved="OnCellSaved">
166+
<SpreadsheetRibbon></SpreadsheetRibbon>
167+
</SfSpreadsheet>
168+
169+
@code {
170+
public byte[] DataSourceBytes { get; set; }
171+
172+
protected override void OnInitialized()
173+
{
174+
string filePath = "wwwroot/Sample.xlsx";
175+
DataSourceBytes = File.ReadAllBytes(filePath);
176+
}
177+
private void OnCellSaved(CellSavedEventArgs args)
178+
{
179+
// Log the cell change, including the action that triggered it.
180+
Console.WriteLine($"Cell {args.Address} changed from '{args.OldValue}' to '{args.Value}' by {args.Action}.");
181+
}
182+
}
183+
{% endhighlight %}
184+
{% endtabs %}
185+
87186
## Cell editing in protected sheet
88187

89188
In a protected sheet, only unlocked ranges can be edited based on the sheet's protection settings. Attempting to modify a locked range triggers an error message, as shown below:
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
---
2+
layout: post
3+
title: Formatting in Blazor Spreadsheet Component | Syncfusion
4+
description: Checkout and learn all about formatting options in the Syncfusion Blazor Spreadsheet component | Syncfusion.
5+
platform: document-processing
6+
control: Spreadsheet
7+
documentation: ug
8+
---
9+
10+
# Formatting in Blazor Spreadsheet Component
11+
12+
Formatting options improve data readability and presentation. The Blazor Spreadsheet component provides various formatting options, which can be categorized into:
13+
14+
* Number Formatting
15+
* Text Formatting
16+
* Cell Formatting
17+
18+
The entire formatting functionality can be globally enabled or disabled using the [`AllowCellFormatting`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AllowCellFormatting) property. By default, `AllowCellFormatting` is set to **true**.
19+
20+
## Number Formatting
21+
22+
Number formatting in the Blazor Spreadsheet component controls how numeric, date, and time values are displayed without altering their underlying data. The component offers Excel-like number formats that are culture-aware, integrate with undo/redo operations, and respect worksheet protection settings. These formats can be applied through the Ribbon toolbar or programmatically.
23+
24+
The number formatting functionality can be globally enabled or disabled using the [`AllowNumberFormatting`](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_AllowNumberFormatting) property. By default, `AllowNumberFormatting` is set to **true**.
25+
26+
### Supported Categories
27+
28+
The Blazor Spreadsheet component provides several built-in number format categories to control how numeric, date, and time values are displayed. These formats are culture-aware and ensure proper rendering of decimal separators, currency symbols, and date/time patterns.
29+
30+
| Category | Example Format String | Result Example |
31+
|---|---|---|
32+
| General | `General` | 1234.567 |
33+
| Number | `#,##0.00` | 1234.57 |
34+
| Currency | `$#,##0.00` | $1,234.57 |
35+
| Accounting | `_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)` | $ 1,234.57 |
36+
| Percentage | `0.00%` | 8.90% |
37+
| Scientific | `0.00E+00` | 1.23E+03 |
38+
| Fraction | `# ?/?` | 123 1/2 |
39+
| Short Date | `m/d/yyyy` | 03/15/2025 |
40+
| Long Date | `dddd, mmmm dd, yyyy` | Saturday, March 15, 2025 |
41+
| Time | `h:mm:ss AM/PM` | 3:45:30 PM |
42+
43+
### Applying Number Formats via the UI
44+
45+
Number formats can be applied through the UI using the following method:
46+
47+
* **Ribbon**: Navigate to the **Home** tab and use the **Number Format** dropdown. This dropdown displays previews of built-in formats based on the current culture.
48+
49+
![Blazor Spreadsheet showing Number Format Dropdown in Ribbon](./images/number-format-ribbon.png)
50+
51+
### Applying Number Formats Programmatically
52+
53+
Number formats can be applied programmatically to the current selection or a specified range using the [NumberFormatAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_NumberFormatAsync_System_String_System_String_) method. This method accepts a format string and an optional cell address.
54+
55+
| Parameter | Type | Description |
56+
| -- | -- | -- |
57+
| format | string | The built-in format or a supported custom pattern. |
58+
| cellAddress | string (Optional) | The address of the target range where the number format was applied (e.g., `"Sheet1!A2:A5"` or `"A2:A5"`).When cellAddress is omitted, the current selection is formatted. |
59+
60+
{% tabs %}
61+
{% highlight razor tabtitle="Index.razor" %}
62+
63+
@using Syncfusion.Blazor.Spreadsheet
64+
65+
<button @onclick="ApplyFormat">Apply number format</button>
66+
<SfSpreadsheet @ref="SpreadsheetInstance" DataSource="DataSourceBytes">
67+
<SpreadsheetRibbon></SpreadsheetRibbon>
68+
</SfSpreadsheet>
69+
70+
@code {
71+
public SfSpreadsheet SpreadsheetInstance;
72+
public byte[] DataSourceBytes { get; set; }
73+
74+
protected override void OnInitialized()
75+
{
76+
string filePath = "wwwroot/Sample.xlsx";
77+
DataSourceBytes = File.ReadAllBytes(filePath);
78+
}
79+
80+
private async Task ApplyFormat()
81+
{
82+
// Apply custom percentage format to range A2:A5
83+
await SpreadsheetInstance.NumberFormatAsync("0.00%", "A2:A5");
84+
// Apply custom short date format to cell D1 on Sheet2
85+
await SpreadsheetInstance.NumberFormatAsync("mm/dd/yyyy", "Sheet2!D1");
86+
}
87+
}
88+
{% endhighlight %}
89+
{% endtabs %}
90+
91+
If the built-in formats do not meet specific requirements, custom patterns can be applied programmatically using the `NumberFormatAsync` method. Currently, a dedicated UI dialog for defining custom formats is not available. They are exclusively supported through the API. Patterns must be compatible with Excel-style format strings.
92+
93+
## Text and Cell Formatting
94+
95+
Text and cell formatting enhances the visual presentation of data by applying styles such as font changes, colors, borders, and alignment to individual cells or cell ranges. This helps organize content and emphasize important information for faster interpretation.
96+
97+
### Text and cell formatting options include:
98+
99+
* **Bold** - Applies a heavier font weight to make the text stand out in the Spreadsheet.
100+
101+
* **Italic** - Slants the text to give it a distinct look, often used for emphasis or to highlight differences.
102+
103+
* **Underline** - Adds a line below the text, commonly used for emphasis or to indicate hyperlinks.
104+
105+
* **Strikethrough** - Draws a line through the text, often used to show completed tasks or outdated information.
106+
107+
* **Font Family** - Changes the typeface of the text (e.g., Arial, Calibri, Times New Roman, and more) to enhance readability or visual appeal.
108+
109+
* **Font Size** - Adjusts the size of the text to create visual hierarchy or improve readability in the Spreadsheet.
110+
111+
* **Font Color** - Changes the color of the text to improve visual hierarchy or to organize information using color codes.
112+
113+
* **Fill Color** - Adds color to the cell background to visually organize data or highlight important information.
114+
115+
* **Horizontal Alignment** - Controls the position of text from left to right within a cell. Options include:
116+
* **Left** - Default for text
117+
* **Center** - Useful for headings
118+
* **Right** - Default for numbers
119+
120+
* **Vertical Alignment** - Controls the position of text from top to bottom within a cell. Options include:
121+
* **Top** – Aligns content to the top of the cell
122+
* **Middle** – Centers content vertically
123+
* **Bottom** – Default alignment
124+
125+
* **Wrap Text** - Displays long content on multiple lines within a single cell, preventing it from overflowing into adjacent cells. To enable text wrapping:
126+
1. Select the target cell or range (e.g., C5).
127+
2. Go to the Home tab.
128+
3. Click Wrap Text in the ribbon to toggle text wrapping for the selected cells.
129+
130+
Text and cell formatting can be applied or removed from a cell or range by using the options available in the component's built-in **Ribbon** under the **Home** tab.
131+
132+
### Borders
133+
134+
Borders visually separate cells and define tables or sections within a worksheet. The Blazor Spreadsheet component supports various border types, styles, colors, and sizes. The available border options are:
135+
136+
| Border Type | Description |
137+
|-------------|-------------|
138+
| Top Border | Applies a border to the top edge of a cell or range of cells. |
139+
| Left Border | Applies a border to the left edge of a cell or range of cells. |
140+
| Right Border | Applies a border to the right edge of a cell or range of cells. |
141+
| Bottom Border | Applies a border to the bottom edge of a cell or range of cells. |
142+
| No Border | Removes all borders from a cell or range of cells. |
143+
| All Border | Applies borders to all sides of a cell or range of cells. |
144+
| Horizontal Border | Applies borders to the top and bottom edges of a cell or range. |
145+
| Vertical Border | Applies borders to the left and right edges of a cell or range. |
146+
| Outside Border | Applies borders to the outer edges of a range of cells. |
147+
| Inside Border | Applies borders to the inner edges of a range of cells |
148+
149+
Border color, size, and style can also be customized. The supported sizes and styles are:
150+
151+
| Type | Description |
152+
|--------|----------------------------------|
153+
| Thin | Specifies a `1px` border size (default). |
154+
| Medium | Specifies a `2px` border size. |
155+
| Thick | Specifies a `3px` border size. |
156+
| Solid | Creates a `solid` border (default). |
157+
| Dashed | Creates a `dashed` border.|
158+
| Dotted | Creates a `dotted` border.|
159+
| Double | Creates a `double` border.|
160+
161+
### Applying Borders via the UI
162+
163+
Borders can be applied through the UI using the following method:
164+
165+
* **Ribbon**: Navigate to the **Home** tab in the Ribbon toolbar and select the **Borders** dropdown. Styling options such as color, size, and style are available within the same menu.
166+
167+
![Blazor Spreadsheet displaying available border options on the Home tab in the Ribbon toolbar](./images/borders.png)
168+
169+
### Applying Borders Programmatically
170+
171+
Borders can be applied programmatically to a specific cell or range of cells using the [SetBordersAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Spreadsheet.SfSpreadsheet.html#Syncfusion_Blazor_Spreadsheet_SfSpreadsheet_SetBordersAsync_Syncfusion_Blazor_Spreadsheet_BorderType_Syncfusion_XlsIO_ExcelLineStyle_System_String_System_String) method. The available parameters in the `SetBordersAsync` method are:
172+
173+
| Parameter | Type | Description |
174+
| -- | -- | -- |
175+
| borderType | BorderType | Specifies the type of border to apply (e.g., `BorderType.OutsideBorders`, `BorderType.AllBorders`, `BorderType.TopBorder`). |
176+
| lineStyle | Syncfusion.XlsIO.ExcelLineStyle | Defines the line style of the border (e.g., `Syncfusion.XlsIO.ExcelLineStyle.Thin`, `Syncfusion.XlsIO.ExcelLineStyle.Medium`, `Syncfusion.XlsIO.ExcelLineStyle.Dashed`). |
177+
| borderColor | string | The border color in hexadecimal or named CSS color format (e.g., `"#000000"`, `"red"`, `"#2196F3"`). |
178+
| cellAddress | string (Optional) | The address of the target cell or range (e.g., `"A1"`, `"A1:C5"`, or `"Sheet2!B2:D4"`). If omitted, the operation targets the current selection. |
179+
180+
{% tabs %}
181+
{% highlight razor tabtitle="Index.razor" %}
182+
@using Syncfusion.Blazor.Spreadsheet
183+
@using Syncfusion.XlsIO
184+
185+
<button @onclick="ApplyBorders">Apply Borders</button>
186+
<SfSpreadsheet @ref="SpreadsheetInstance" DataSource="DataSourceBytes"></SfSpreadsheet>
187+
188+
@code {
189+
public SfSpreadsheet SpreadsheetInstance { get; set; }
190+
public byte[] DataSourceBytes { get; set; }
191+
192+
protected override void OnInitialized()
193+
{
194+
string filePath = "wwwroot/Sample.xlsx";
195+
DataSourceBytes = File.ReadAllBytes(filePath);
196+
}
197+
public async Task ApplyBorders()
198+
{
199+
await SpreadsheetInstance.SetBordersAsync(BorderType.OutsideBorders, ExcelLineStyle.Medium, "#FF0000", "A1:C5");
200+
await SpreadsheetInstance.SetBordersAsync(BorderType.AllBorders, ExcelLineStyle.Dashed, "#0000FF", "B2:D4");
201+
}
202+
}
203+
{% endhighlight %}
204+
{% endtabs %}
205+
206+
### Limitations
207+
208+
* Conditional formatting is currently not supported in the Blazor Spreadsheet component.
209+
* A custom number format UI dialog is not available, custom formats must be applied using the API.
121 KB
Loading
3.86 KB
Loading
101 KB
Loading

0 commit comments

Comments
 (0)