Search results

Cell Range in Angular Spreadsheet component

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 in cell, 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.

Source
Preview
app.component.ts
app.module.ts
datasource.ts
main.ts
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { dataSource } from './datasource';

@Component({
    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;

    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 { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        SpreadsheetAllModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
/**
 * Wrap text data source
 */
export let dataSource: Object[] = [
  {
      'No': '1',
      'Released on': 1994,
      'Title': 'Forrest Gump',
      'Rating': '5 Stars',
      'Casts': 'Tom Hanks, Robin Wright, Gary Sinise',
      'Directed By': 'Robert Zemeckis',
      'Genre': 'Drama',
      'Comments': 'Based on the 1986 novel of the same name by Winston Groom'
  },
  {
      'No': '2',
      'Released on': 1946,
      'Title': 'It’s a Wonderful Life',
      'Rating': '2 Stars',
      'Casts': 'James Stewart, Donna Reed, Lionel Barrymore',
      'Directed By': 'Frank Capra',
      'Genre': 'Drama',
      'Comments': 'Colorized version'
  },
  {
      'No': '3',
      'Released on': 1988,
      'Title': 'Big',
      'Rating': '4 Stars',
      'Casts': 'Tom Hanks, Elizabeth Perkins, Robert Loggia',
      'Directed By': 'Penny Marshall',
      'Genre': 'Comedy',
      'Comments': 'A thirteen-year-old boy wishes to be big, and his wish comes true.'
  },
  {
      'No': '4',
      'Released on': 1954,
      'Title': 'Rear Window',
      'Rating': '4 Stars',
      'Casts': 'James Stewart, Grace Kelly, Wendell Corey',
      'Directed By': 'Alfred Hitchcock',
      'Genre': 'Suspense',
      'Comments': 'Truly suspenseful and masterfully crafted'
  }
];
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

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 and colSpan property in cell 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.

Source
Preview
app.component.ts
app.module.ts
datasource.ts
main.ts
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { dataSource } from './datasource';

@Component({
    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;

    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 { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        SpreadsheetAllModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
/**
 * Merge cells data source
 */
export let dataSource: Object[] = [
    {
        'Employee ID': 10001,
        'Employee Name': 'Davolio',
        '9:00 AM': 'Analysis Tasks',
        '9:30 AM': 'Analysis Tasks',
        '10:00 AM': 'Team Meeting',
        '10:30 AM': 'Testing',
        '11:00 AM': 'Development',
        '11:30 AM': 'Development',
        '12:00 PM': 'Development',
        '12:30 PM': 'Support',
        '1:00 PM': 'Lunch Break',
        '1:30 PM': 'Lunch Break',
        '2:00 PM': 'Lunch Break',
        '2:30 PM': 'Testing',
        '3:00 PM': 'Testing',
        '3:30 PM': 'Development',
        '4:00 PM': 'Conference',
        '4:30 PM': 'Team Meeting',
        '5:00 PM': 'Team Meeting'
    },
    {
        'Employee ID': 10002,
        'Employee Name': 'Buchanan',
        '9:00 AM': 'Task Assign',
        '9:30 AM': 'Support',
        '10:00 AM': 'Support',
        '10:30 AM': 'Support',
        '11:00 AM': 'Testing',
        '11:30 AM': 'Testing',
        '12:00 PM': 'Testing',
        '12:30 PM': 'Testing',
        '1:00 PM': 'Lunch Break',
        '1:30 PM': 'Lunch Break',
        '2:00 PM': 'Lunch Break',
        '2:30 PM': 'Development',
        '3:00 PM': 'Development',
        '3:30 PM': 'Check Mail',
        '4:00 PM': 'Check Mail',
        '4:30 PM': 'Team Meeting',
        '5:00 PM': 'Team Meeting'
    },
    {
        'Employee ID': 10003,
        'Employee Name': 'Fuller',
        '9:00 AM': 'Check Mail',
        '9:30 AM': 'Check Mail',
        '10:00 AM': 'Check Mail',
        '10:30 AM': 'Analysis Tasks',
        '11:00 AM': 'Analysis Tasks',
        '11:30 AM': 'Support',
        '12:00 PM': 'Support',
        '12:30 PM': 'Support',
        '1:00 PM': 'Lunch Break',
        '1:30 PM': 'Lunch Break',
        '2:00 PM': 'Lunch Break',
        '2:30 PM': 'Development',
        '3:00 PM': 'Development',
        '3:30 PM': 'Team Meeting',
        '4:00 PM': 'Team Meeting',
        '4:30 PM': 'Development',
        '5:00 PM': 'Development'
    },
    {
        'Employee ID': 10004,
        'Employee Name': 'Leverling',
        '9:00 AM': 'Testing',
        '9:30 AM': 'Check Mail',
        '10:00 AM': 'Check Mail',
        '10:30 AM': 'Support',
        '11:00 AM': 'Testing',
        '11:30 AM': 'Testing',
        '12:00 PM': 'Testing',
        '12:30 PM': 'Testing',
        '1:00 PM': 'Lunch Break',
        '1:30 PM': 'Lunch Break',
        '2:00 PM': 'Lunch Break',
        '2:30 PM': 'Development',
        '3:00 PM': 'Development',
        '3:30 PM': 'Check Mail',
        '4:00 PM': 'Conference',
        '4:30 PM': 'Conference',
        '5:00 PM': 'Team Meeting'
    },
    {
        'Employee ID': 10005,
        'Employee Name': 'Peacock',
        '9:00 AM': 'Task Assign',
        '9:30 AM': 'Task Assign',
        '10:00 AM': 'Task Assign',
        '10:30 AM': 'Task Assign',
        '11:00 AM': 'Check Mail',
        '11:30 AM': 'Support',
        '12:00 PM': 'Support',
        '12:30 PM': 'Support',
        '1:00 PM': 'Lunch Break',
        '1:30 PM': 'Lunch Break',
        '2:00 PM': 'Lunch Break',
        '2:30 PM': 'Development',
        '3:00 PM': 'Development',
        '3:30 PM': 'Team Meeting',
        '4:00 PM': 'Team Meeting',
        '4:30 PM': 'Testing',
        '5:00 PM': 'Testing'
    }
];
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

See Also