|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Managing Cell Ranges in Blazor Spreadsheet component | Syncfusion |
| 4 | +description: Checkout and learn to manage cell range features such as formatting, autofill, and clear options in the Syncfusion Blazor Spreadsheet component and more. |
| 5 | +platform: Blazor |
| 6 | +control: Spreadsheet |
| 7 | +documentation: ug |
| 8 | +--- |
| 9 | + |
| 10 | +# Managing Cell Ranges in Blazor Spreadsheet component |
| 11 | + |
| 12 | +A cell range refers to a group of selected cells in a Spreadsheet that can be manipulated or processed collectively. |
| 13 | + |
| 14 | +## Cell formatting |
| 15 | + |
| 16 | +Cell formatting enhances the visual presentation of data in a Spreadsheet by applying styles such as font changes, colors, borders, and alignment to individual cells or cell ranges. This helps in organizing and emphasizing important information effectively. |
| 17 | + |
| 18 | +Cell formatting options include: |
| 19 | + |
| 20 | +* **Bold** - Applies a heavier font weight to make the text stand out in the Spreadsheet. |
| 21 | + |
| 22 | +* **Italic** - Slants the text to give it a distinct look, often used for emphasis or to highlight differences. |
| 23 | + |
| 24 | +* **Underline** - Adds a line below the text, commonly used for emphasis or to indicate hyperlinks. |
| 25 | + |
| 26 | +* **Strikethrough** - Draws a line through the text, often used to show completed tasks or outdated information. |
| 27 | + |
| 28 | +* **Font Family** - Changes the typeface of the text (e.g., Arial, Calibri, Times New Roman, and more) to enhance readability or visual appeal. |
| 29 | + |
| 30 | +* **Font Size** - Adjusts the size of the text to create visual hierarchy or improve readability in the Spreadsheet. |
| 31 | + |
| 32 | +* **Font Color** - Changes the color of the text to improve visual hierarchy or to organize information using color codes. |
| 33 | + |
| 34 | +* **Fill Color** - Adds color to the cell background to visually organize data or highlight important information. |
| 35 | + |
| 36 | +* **Horizontal Alignment** - Controls the position of text from left to right within a cell. Options include: |
| 37 | + * **Left** - Default for text |
| 38 | + * **Center** - Useful for headings |
| 39 | + * **Right** - Default for numbers |
| 40 | + |
| 41 | +* **Vertical Alignment** - Controls the position of text from top to bottom within a cell. Options include: |
| 42 | + * **Top** – Aligns content to the top of the cell |
| 43 | + * **Middle** – Centers content vertically |
| 44 | + * **Bottom** – Default alignment |
| 45 | + |
| 46 | +* **Wrap Text** - Displays long content on multiple lines within a single cell, preventing it from overflowing into adjacent cells. |
| 47 | + |
| 48 | +Cell formatting can be applied to or removed from a cell or range of cells by using the formatting options available in the Ribbon toolbar under the **Home** tab. |
| 49 | + |
| 50 | +## Autofill |
| 51 | + |
| 52 | +Autofill is used to fill cells with data based on adjacent cells. It follows patterns from adjacent cells when available, eliminating the need to enter repeated 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 the autofill support. |
| 53 | + |
| 54 | +> * The default value of the `AllowAutofill` property is **true**. |
| 55 | +
|
| 56 | +Autofill can be performed in one of the following ways: |
| 57 | + |
| 58 | +* Drag and drop the cell using the fill handle element. |
| 59 | +* Use the `AutofillAsync()` method programmatically. |
| 60 | + |
| 61 | +The available parameters in the `AutofillAsync()` method are: |
| 62 | + |
| 63 | +| Parameter | Type | Description | |
| 64 | +| -- | -- | -- | |
| 65 | +| fillRange | string | Specifies the fill range. | |
| 66 | +| dataRange | string | Specifies the data range. | |
| 67 | +| direction | string | Specifies the direction ("Up", "Right", "Down", and "Left") to be filled. | |
| 68 | + |
| 69 | +### Implementing autofill programmatically |
| 70 | + |
| 71 | +{% tabs %} |
| 72 | +{% highlight razor tabtitle="Index.razor" %} |
| 73 | + |
| 74 | +@using Syncfusion.Blazor.Spreadsheet |
| 75 | + |
| 76 | +<button @onclick="AutofillRangeHandler">Autofill</button> |
| 77 | +<SfSpreadsheet @ref="spreadsheetObj" DataSource="DataSourceBytes"> |
| 78 | + <SpreadsheetRibbon></SpreadsheetRibbon> |
| 79 | +</SfSpreadsheet> |
| 80 | + |
| 81 | +@code { |
| 82 | + public byte[] DataSourceBytes { get; set; } |
| 83 | + public SfSpreadsheet spreadsheetObj; |
| 84 | + |
| 85 | + protected override void OnInitialized() |
| 86 | + { |
| 87 | + string filePath = "wwwroot/Sample.xlsx"; |
| 88 | + DataSourceBytes = File.ReadAllBytes(filePath); |
| 89 | + } |
| 90 | + |
| 91 | + public async Task AutofillRangeHandler() |
| 92 | + { |
| 93 | + // Basic usage with only the fill range parameter. |
| 94 | + await spreadsheetObj.AutofillAsync("B7:B8"); |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +{% endhighlight %} |
| 99 | +{% endtabs %} |
| 100 | + |
| 101 | +The following illustration demonstrates the use of autofill in the Spreadsheet component. |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +## Clear |
| 106 | + |
| 107 | +Clear support helps clear the cell contents (formulas and data) and formats (including number formats) in a Spreadsheet. When **Clear All** is applied, both the contents and the formats will be cleared simultaneously. |
| 108 | + |
| 109 | +### Applying the clear functionality |
| 110 | + |
| 111 | +The clear support can be applied using the following way: |
| 112 | + |
| 113 | +* Select the **Clear** icon in the Ribbon toolbar under the **Home** tab. |
| 114 | + |
| 115 | +| Options | Uses | |
| 116 | +| -- | -- | |
| 117 | +| **Clear All** | Used to clear all contents, formats, and hyperlinks. | |
| 118 | +| **Clear Formats** | Used to clear the formats (including number formats) in a cell. | |
| 119 | +| **Clear Contents** | Used to clear the contents (formulas and data) in a cell. | |
| 120 | +| **Clear Hyperlinks** | Used to clear the hyperlink in a cell. | |
| 121 | + |
| 122 | +The following image displays the clear options available in the Ribbon toolbar under the **Home** tab of the Blazor Spreadsheet. |
| 123 | + |
| 124 | + |
0 commit comments