Cell Range in Angular Spreadsheet Component
15 Dec 202424 minutes to read
A group of cells in a sheet is known as cell range.
Wrap text
Wrap text allows you to display large content as multiple lines in a single cell. By default, the wrap text support is enabled. Use the allowWrap
property to enable or disable the wrap text support in spreadsheet.
Wrap text can be applied or removed to a cell or range of cells in the following ways,
- Using the
wrap
property incell
, you can enable or disable wrap text to a cell at initial load. - Select or deselect wrap button from ribbon toolbar to apply or remove the wrap text to the selected range.
- Using the
wrap
method, you can apply or remove the wrap text once the component is loaded.
The following code example shows the wrap text functionality in spreadsheet.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { dataSource } from './datasource';
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #spreadsheet (created)="created()" [showFormulaBar]="false">
<e-sheets>
<e-sheet name="Movie List">
<e-ranges>
<e-range [dataSource]="data"></e-range>
</e-ranges>
<e-columns>
<e-column [index]=1 [width]=100></e-column>
<e-column [width]=140></e-column>
<e-column [width]=90></e-column>
<e-column [width]=150></e-column>
<e-column [width]=120></e-column>
<e-column [width]=90></e-column>
<e-column [width]=180></e-column>
</e-columns>
<e-rows>
<e-row [height]=30></e-row>
<e-row>
<e-cells>
<e-cell [index]=7 [wrap]="true"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell [index]=7 [wrap]="true"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell [index]=7 [wrap]="true"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell [index]=7 [wrap]="true"></e-cell>
</e-cells>
</e-row>
</e-rows>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('spreadsheet')
spreadsheetObj: SpreadsheetComponent | undefined;
data: object[] = dataSource;
created() {
this.spreadsheetObj!.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
this.spreadsheetObj!.cellFormat({ verticalAlign: 'middle' }, 'A1:H5');
this.spreadsheetObj!.cellFormat({ textAlign: 'center' }, 'A2:B5');
this.spreadsheetObj!.cellFormat({ textAlign: 'center' }, 'D2:D5');
// To wrap the cells from E2 to E5 range
this.spreadsheetObj!.wrap('E2:E5');
// To unwrap the H3 cell
this.spreadsheetObj!.wrap('H3', false);
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Limitations of Wrap text
The following features have some limitations in wrap text:
- Sorting with wrap text applied data.
- Merge with wrap text.
Merge cells
Merge cells allows users to span two or more cells in the same row or column into a single cell. When cells with multiple values are merged, top-left most cell data will be the data for the merged cell. By default, the merge cells option is enabled. Use allowMerge
property to enable or disable the merge cells option in spreadsheet.
You can merge the range of cells in the following ways,
- Set the
rowSpan
andcolSpan
property incell
to merge the number of cells at initial load. - Select the range of cells and apply merge by selecting the desired option from ribbon toolbar.
- Use
merge
method to merge the range of cells, once the component is loaded.
The available merge options in spreadsheet are,
Type | Action |
---|---|
Merge All | Combines all the cells in a range in to a single cell (default). |
Merge Horizontally | Combines cells in a range as row-wise. |
Merge Vertically | Combines cells in a range as column-wise. |
UnMerge | Splits the merged cells into multiple cells. |
The following code example shows the merge cells operation in spreadsheet.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { dataSource } from './datasource';
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #spreadsheet (created)="created()" [showFormulaBar]="false">
<e-sheets>
<e-sheet name="Merge Cells">
<e-ranges>
<e-range [dataSource]="data"></e-range>
</e-ranges>
<e-columns>
<e-column [width]=90></e-column>
<e-column [width]=150></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=120></e-column>
<e-column [width]=120></e-column>
<e-column [width]=120></e-column>
<e-column [width]=120></e-column>
<e-column [width]=120></e-column>
<e-column [width]=120></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
</e-columns>
<e-rows>
<e-row [height]=35></e-row>
<e-row [height]=35>
<e-cells>
<!-- Merging the 2nd cells of rows 2 and 3 through cell binding. -->
<e-cell [index]=1 [rowSpan]=2></e-cell>
<!-- Merging the 2nd row's 3rd and 4th cells through cell binding. -->
<e-cell [colSpan]=2></e-cell>
<!-- Merging the 2nd row's 7th, 8th and 9th cells through cell binding. -->
<e-cell [index]=6 [colSpan]=3></e-cell>
<!-- Merging the 2nd and 3rd rows 11th, 12th and 13th cells through cell binding. -->
<e-cell [index]=10 [rowSpan]=2 [colSpan]=3></e-cell>
<e-cell [index]=13 [colSpan]=2></e-cell>
<e-cell [index]=17 [colSpan]=2></e-cell>
</e-cells>
</e-row>
<e-row [height]=35>
<e-cells>
<e-cell [index]=3 [colSpan]=3></e-cell>
<e-cell [index]=6 [colSpan]=4></e-cell>
<e-cell [index]=13 [colSpan]=3></e-cell>
<e-cell [index]=17 [colSpan]=2></e-cell>
</e-cells>
</e-row>
<e-row [height]=35>
<e-cells>
<e-cell [index]=2 [colSpan]=3></e-cell>
<e-cell [index]=5 [colSpan]=2></e-cell>
<e-cell [index]=7 [colSpan]=3></e-cell>
<e-cell [index]=15 [colSpan]=2></e-cell>
<e-cell [index]=17 [colSpan]=2></e-cell>
</e-cells>
</e-row>
<e-row [height]=35>
<e-cells>
<e-cell [index]=2 [colSpan]=3></e-cell>
<e-cell [index]=6 [colSpan]=4></e-cell>
<e-cell [index]=16 [colSpan]=2></e-cell>
</e-cells>
</e-row>
<e-row [height]=35>
<e-cells>
<e-cell [index]=2 [colSpan]=4></e-cell>
<e-cell [index]=7 [colSpan]=3></e-cell>
<e-cell [index]=15 [colSpan]=2></e-cell>
<e-cell [index]=17 [colSpan]=2></e-cell>
</e-cells>
</e-row>
</e-rows>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('spreadsheet')
spreadsheetObj: SpreadsheetComponent | undefined;
data: object[] = dataSource;
created() {
this.spreadsheetObj!.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:S1');
this.spreadsheetObj!.numberFormat('h:mm AM/PM', 'C1:S1');
this.spreadsheetObj!.cellFormat({ verticalAlign: 'middle' }, 'A1:S11');
// Merging the `K4:M4` cells using method
this.spreadsheetObj!.merge('K4:M4');
// Merging the 5th and 6th row cells across 11th, 12th and 13th column
this.spreadsheetObj!.merge('K5:M6', 'Vertically');
// Merging the 18th and 19th column cells across 2nd, 3rd and 4th row
this.spreadsheetObj!.merge('N4:O6', 'Horizontally');
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Limitations of Merge
The following features have some limitations in Merge:
- Merge with filter.
- Merge with wrap text.
Data Validation
Data Validation is used to restrict the user from entering the invalid data. You can use the allowDataValidation
property to enable or disable data validation.
- The default value for
allowDataValidation
property istrue
.
Apply Validation
You can apply data validation to restrict the type of data or the values that users enter into a cell.
You can apply data validation by using one of the following ways,
- Select the Data tab in the Ribbon toolbar, and then choose the Data Validation item.
- Use the
addDataValidation()
method programmatically.
Clear Validation
Clear validation feature is used to remove data validations from the specified ranges or the whole worksheet.
You can clear data validation rule by one of the following ways,
- Select the Data tab in the Ribbon toolbar, and then choose the Clear Validation item.
- Use the
removeDataValidation()
method programmatically.
Highlight Invalid Data
Highlight invalid data feature is used to highlight the previously entered invalid values.
You can highlight an invalid data by using one of the following ways,
- Select the Data tab in the Ribbon toolbar, and then choose the Highlight Invalid Data item.
- Use the
addInvalidHighlight()
method programmatically.
Clear Highlighted Invalid Data
Clear highlight feature is used to remove the highlight from invalid cells.
You can clear the highlighted invalid data by using the following ways,
- Select the Data tab in the Ribbon toolbar, and then choose the Clear Highlight item.
- Use the
removeInvalidHighlight()
method programmatically.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { conditionalFormatData } from './datasource';
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #default [openUrl]="openUrl" [saveUrl]="saveUrl" (created)="created()">
<e-sheets>
<e-sheet name="PriceDetails" >
<e-rows>
<e-row>
<e-cells>
<e-cell value="Seller Name" [style]="style"></e-cell>
<e-cell value="Customer Id" [style]="style"></e-cell>
<e-cell value="Customer Name" [style]="style"></e-cell>
<e-cell value="Product Name" [style]="style"></e-cell>
<e-cell value="Product Price" [style]="style"></e-cell>
<e-cell value="Sales Date" [style]="style"></e-cell>
<e-cell value="Billing Time" [style]="style"></e-cell>
<e-cell value="Total Price" [style]="style"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="John"></e-cell>
<e-cell value="1" [validation]="validation"></e-cell>
<e-cell value="Nash"></e-cell>
<e-cell value="Digger" [validation]="listValidation"></e-cell>
<e-cell value="50000" [validation]="listValidation1"></e-cell>
<e-cell value="04/11/2019"></e-cell>
<e-cell value="11:34:32 AM"></e-cell>
<e-cell value="1,45,000.00"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="Mike"></e-cell>
<e-cell value="2" [validation]="validation"></e-cell>
<e-cell value="Jim" ></e-cell>
<e-cell value="Cherrypicker" [validation]="listValidation2"></e-cell>
<e-cell value="45000" [validation]="validation"></e-cell>
<e-cell value="04/11/2019"></e-cell>
<e-cell value="10:15:00 AM"></e-cell>
<e-cell value="1,40,040.00"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="shane"></e-cell>
<e-cell value="3" [validation]="validation"></e-cell>
<e-cell value="Sean"></e-cell>
<e-cell value="Kango" [validation]="validation3"></e-cell>
<e-cell value="450" [validation]="validation4"></e-cell>
<e-cell value="06/25/2019"></e-cell>
<e-cell value="01:30:11 PM"></e-cell>
<e-cell value="545.00"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="John"></e-cell>
<e-cell value="1" [validation]="validation"></e-cell>
<e-cell value="Nash"></e-cell>
<e-cell value="JCB" [validation]="validation5"></e-cell>
<e-cell value="90000" [validation]="validation6"></e-cell>
<e-cell value="09/22/2019"></e-cell>
<e-cell value="12:30:02 PM"></e-cell>
<e-cell value="1,00,095.00"></e-cell>
</e-cells>
</e-row>
</e-rows>
<e-columns>
<e-column [width]=88></e-column>
<e-column [width]=88></e-column>
<e-column [width]=106></e-column>
<e-column [width]=98></e-column>
<e-column [width]=88></e-column>
<e-column [width]=86></e-column>
<e-column [width]=81></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('default')
spreadsheetObj: SpreadsheetComponent | undefined;
public style: any = { fontWeight: "bold", textAlign: "center" };
public validation = { type: 'WholeNumber', operator: 'NotEqualTo', value1: '1' };
public listValidation = { type: 'List', value1: 'Digger, Digger, Cherrypicker' };
public listValidation1 = { type: 'List', value1: '50000,50000,45000' };
public listValidation2 = { type: 'List', value1: 'Cherrypicker, JCB, Wheelbarrow' };
public validation2 = { type: 'List', value1: '45000,90000,40' };
public validation3 = { type: 'List', value1: 'Kango, Ropes' };
public validation4 = { type: 'List', value1: '450, 95' };
public validation5 = { type: 'List', value1: 'JCB, Ropes, scaffolding' };
public validation6 = { type: 'List', value1: '90000, 95, 10000' };
openUrl: any;
saveUrl: any;
created() {
//Add Data validation to range.
this.spreadsheetObj!.addDataValidation({ type: 'TextLength', operator: 'LessThanOrEqualTo', value1: '4' }, 'A2:A5');
this.spreadsheetObj!.addDataValidation({ type: 'WholeNumber', operator: 'NotEqualTo', value1: '1' }, 'B2:B5');
this.spreadsheetObj!.addDataValidation({ type: 'Date', operator: 'NotEqualTo', value1: '04/11/2019' }, 'F2:F5');
this.spreadsheetObj!.addDataValidation({ type: 'Time', operator: 'Between', value1: '10:00:00 AM', value2: '11:00:00 AM' }, 'G2:G5');
this.spreadsheetObj!.addDataValidation({ type: 'Decimal', operator: 'LessThan', value1: '100000.00' }, 'H2:H5');
//Highlight Invalid Data.
this.spreadsheetObj!.addInvalidHighlight('A1:H5');
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Custom Data validation
The Spreadsheet supports custom data validation, allowing users to define their own validation rules for specific cells or ranges. This feature enables you to set conditions that the entered data must meet, making it particularly useful when predefined validation options, such as numbers, dates, or lists, are insufficient.
With custom validation, you can enforce rules using logical expressions or formulas, ensuring that only valid data is entered into the Spreadsheet.
For example, consider a scenario where you want to ensure that a cell contains a number between 10 and 100. To achieve this, define a validation rule using a formula that checks if the entered value is greater than 10 and less than 100. The formula for this validation is =AND(A1>10, A1<100), where A1 refers to the cell being validated.
When this rule is applied, the Spreadsheet evaluates the entered value against the formula. If a user enters a value outside the specified range, an alert notifies them of the invalid input. This helps users correct errors efficiently and ensures that only desired values are accepted.
You can apply custom data validation using two methods.
- The first is through the Data Validation dialog in the Ribbon toolbar. Navigate to the Data tab, select the Data Validation option, and choose the Custom type from the Allow dropdown menu.
- The second method is programmatically, using the
addDataValidation()
method, which allows developers to set custom rules dynamically via code.
The following code example demonstrates how to add custom data validation with a formula in a Spreadsheet.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
@Component({
imports: [SpreadsheetAllModule],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #default [openUrl]="openUrl" [saveUrl]="saveUrl" (created)="created()">
<e-sheets>
<e-sheet name="PriceDetails" >
<e-rows>
<e-row>
<e-cells>
<e-cell value="Seller Name" [style]="style"></e-cell>
<e-cell value="Customer Id" [style]="style"></e-cell>
<e-cell value="Customer Name" [style]="style"></e-cell>
<e-cell value="Product Name" [style]="style"></e-cell>
<e-cell value="Product Price" [style]="style"></e-cell>
<e-cell value="Total Price" [style]="style"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="John"></e-cell>
<e-cell value="101"></e-cell>
<e-cell value="Nash"></e-cell>
<e-cell value="Digger"></e-cell>
<e-cell value="50000"></e-cell>
<e-cell value="1,45,000.00"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="Mike"></e-cell>
<e-cell value="25"></e-cell>
<e-cell value="Jim"></e-cell>
<e-cell value="Cherrypicker"></e-cell>
<e-cell value="45000"></e-cell>
<e-cell value="1,40,040.00"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="shane"></e-cell>
<e-cell value="35"></e-cell>
<e-cell value="Sean"></e-cell>
<e-cell value="Kango"></e-cell>
<e-cell value="35000"></e-cell>
<e-cell value="1,54,500.00"></e-cell>
</e-cells>
</e-row>
<e-row>
<e-cells>
<e-cell value="John"></e-cell>
<e-cell value="101"></e-cell>
<e-cell value="Nash"></e-cell>
<e-cell value="JCB"></e-cell>
<e-cell value="90000"></e-cell>
<e-cell value="1,00,095.00"></e-cell>
</e-cells>
</e-row>
</e-rows>
<e-columns>
<e-column [width]=88></e-column>
<e-column [width]=88></e-column>
<e-column [width]=106></e-column>
<e-column [width]=98></e-column>
<e-column [width]=81></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('default')
spreadsheetObj: SpreadsheetComponent | undefined;
public style: any = { fontWeight: "bold", textAlign: "center" };
openUrl: any;
saveUrl: any;
created() {
//Add Data validation to range.
this.spreadsheetObj!.addDataValidation({ type: 'Custom', value1: '=AND(B2>10, B2<100)' }, 'E2:E5');
//Highlight Invalid Data.
this.spreadsheetObj!.addInvalidHighlight('E2:E5');
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Limitations of Data validation
The following features have some limitations in Data Validation:
- Entire row data validation.
- Insert row between the data validation.
- Copy/paste with data validation.
- Delete cells between data validation applied range.
Auto Fill
Auto Fill is used to fill the cells with data based on adjacent cells. It also follows a pattern from adjacent cells if available. There is no need to enter the repeated data manually. You can use allowAutoFill
property to enable/disable the auto fill support. You can also use showFillOptions
property to enable/disable the fill option and fillType
property to change the default auto fill option which is available in autoFillSettings
.
You can do this by one of the following ways,
- Using “AutoFillOptions” menu which is open, while drag and drop the cell using fill handle element.
- Use the autoFill() method programmatically.
The available parameters in autoFill()
method are,
Parameter | Type | Description |
---|---|---|
fillRange | string |
Specifies the fill range. |
dataRange | string |
Specifies the data range. |
direction | AutoFillDirection |
Specifies the direction(“Up”,”Right”,”Down”,”Left”)to be filled. |
fillType | AutoFillType |
Specifies the fill type(“CopyCells”,”FillSeries”,”FillFormattingOnly”,”FillWithoutFormatting”) for autofill action. |
In Auto Fill we have following options,
- Copy Cells
- Fill Series
- Fill Formatting Only
- Fill Without Formatting
- The default auto fill option is “FillSeries” which can be referred from
fillType
property.
Copy Cells
To copy the selected cell content to the adjacent cells. You can do this by one of the following ways,
- Using fill handle to select the adjacent cell range and “Copy Cells” option in “AutoFillOptions” menu to fill the adjacent cells.
- Using “CopyCells” as fill type in
autoFill
method to fill the adjacent cells.
Fill Series
To fill the series of numbers, characters, or dates based on selected cell content to the adjacent cells with their formats.
You can do this by one of the following ways,
- Using fill handle to select the adjacent cell range and “Fill Series” option in “AutoFillOptions” menu to fill the adjacent cells.
- Using “FillSeries” as fill type in
autoFill
method to fill the adjacent cells.
Fill Formatting Only
To fill the cell style and number formatting based on the selected cell content to the adjacent cells without their content.
You can do this by one of the following ways,
- Using fill handle to select the adjacent cell range and “Fill Formatting Only” option in “AutoFillOptions” menu to fill the adjacent cells.
- Using “FillFormattingOnly” as fill type in
autoFill
method to fill the adjacent cells.
Fill Without Formatting
To fill series of numbers, characters, or dates based on the selected cells to the adjacent cells without their formats.
You can do this by one of the following ways,
- Using fill handle to select the adjacent cell range and “Fill Without Formatting” option in “AutoFillOptions” menu to fill the adjacent cells.
- Using “FillWithoutFormatting” as fill type in
autoFill
method to fill the adjacent cells.
In the following sample, you can enable/disable the fill option on the button click event by using the showFillOptions
property in autoFillSettings
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { enableRipple } from '@syncfusion/ej2-base';
import { defaultData } from './datasource';
enableRipple(true);
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<div>
<button class='e-btn' (click)='onclick()'>Change showFillOptions</button>
<ejs-spreadsheet #spreadsheet (created)="created()" >
<e-sheets>
<e-sheet name="Price Details">
<e-ranges>
<e-range [dataSource]="budgetData"></e-range>
</e-ranges>
<e-columns>
<e-column [width]=130></e-column>
<e-column [width]=100></e-column>
<e-column [width]=100></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet></div>`
})
export class AppComponent {
@ViewChild('spreadsheet')
spreadsheetObj: SpreadsheetComponent | undefined;
budgetData: object[] = defaultData;
onclick(): void {
var showFillOptions = this.spreadsheetObj!.autoFillSettings.showFillOptions;
this.spreadsheetObj!.autoFillSettings.showFillOptions = !showFillOptions; //To change whether fill options need to be shown or not.
}
created() {
this.spreadsheetObj!.cellFormat({ backgroundColor: '#357cd2', color: '#fff', fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
this.spreadsheetObj!.autoFill('D4:D11','D2:D3', 'Down','CopyCells');
this.spreadsheetObj!.autoFill('E4:E11','E2:E3','Down','FillSeries');
this.spreadsheetObj!.autoFill('B4:B11','B2:B3','Down','FillFormattingOnly');
this.spreadsheetObj!.autoFill('C4:C11','C2:C3','Down','FillWithoutFormatting');
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Limitations of Autofill
The following features have some limitations in Autofill:
- Flash Fill option in Autofill feature.
- Fill with Conditional Formatting applied cells.
Clear
Clear feature helps you to clear the cell contents (formulas and data), formats (including number formats, conditional formats, and borders) in a spreadsheet. When you apply clear all, both the contents and the formats will be cleared simultaneously.
Apply Clear Feature
You can apply clear feature by using one of the following ways,
- Select the clear icon in the Ribbon toolbar under the Home Tab.
- Using the
clear()
method to clear the values.
Clear has the following types in the spreadsheet,
Options | Uses |
---|---|
Clear All |
Used to clear all contents, formats, and hyperlinks. |
Clear Formats |
Used to clear the formats (including number formats, conditional formats, and borders) in a cell. |
Clear Contents |
Used to clear the contents (formulas and data) in a cell. |
Clear Hyperlinks |
Used to clear the hyperlink in a cell. |
Methods
Clear the cell contents and formats in the Spreadsheet document by using the clear method. The clear method has type
and range
as parameters. The following code example shows how to clear the cell contents and formats in the button click event.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { DropDownButtonModule } from '@syncfusion/ej2-angular-splitbuttons'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, OnInit,ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { ItemModel, MenuEventArgs } from '@syncfusion/ej2-angular-splitbuttons';
import { data } from './datasource';
@Component({
imports: [
DropDownButtonModule,
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: "<button ejs-dropdownbutton [items]='items' content='Clear' (select)='itemSelect($event)'></button> <ejs-spreadsheet #spreadsheet (created)='created()'> <e-sheets> <e-sheet> <e-ranges> <e-range [dataSource]='data'></e-range></e-ranges><e-columns><e-column [width]=90></e-column><e-column [width]=100></e-column><e-column [width]=96></e-column><e-column [width]=120></e-column><e-column [width]=130></e-column><e-column [width]=120></e-column></e-columns></e-sheet></e-sheets></ejs-spreadsheet>"
})
export class AppComponent implements OnInit {
public data?: object[];
@ViewChild('spreadsheet') public spreadsheetObj?: SpreadsheetComponent;
ngOnInit(): void {
this.data = data;
}
public items: ItemModel[] = [
{
text: "Clear All"
},
{
text: "Clear Formats"
},
{
text: "Clear Contents"
},
{
text: "Clear Hyperlinks"
}];
created() {
this.spreadsheetObj!.cellFormat({ fontWeight: 'bold', fontSize: '12pt'}, 'A1:E1');
this.spreadsheetObj!.cellFormat({ color: '#10c469' }, 'B1:B10');
}
public itemSelect(args: MenuEventArgs) {
if (args.item.text === 'Clear All')
this.spreadsheetObj!.clear({ type: 'Clear All', range: 'D1:D10' }); // Clear the content, formats and hyperlinks applied in the provided range.
if (args.item.text === 'Clear Formats')
this.spreadsheetObj!.clear({ type: 'Clear Formats', range: 'B1:B10' }); // Clear the formats applied in the provided range
if (args.item.text === 'Clear Contents')
this.spreadsheetObj!.clear({ type: 'Clear Contents', range: 'A1:A10' }); // Clear the content in the provided range
if (args.item.text === 'Clear Hyperlinks')
this.spreadsheetObj!.clear({ type: 'Clear Hyperlinks', range: 'F2:F6' }); // Clear the hyperlinks applied in the provided range
}
};
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Note
You can refer to our Angular Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our Angular Spreadsheet example to knows how to present and manipulate data.