# spreadsheet-editor-cell-formatting

> Spreadsheet sample demonstrating cell formatting feature by applying different styles to a range of cells.

**Framework:** angular  **Component:** Spreadsheet  **Variant:** cell-formatting

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/angular/spreadsheet-editor-cell-formatting.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-angular-spreadsheet
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/spreadsheet-editor-cell-formatting/spreadsheet-editor.component.html

```html
<div class="control-section">
    <ejs-spreadsheet #cellFormat [showRibbon]="false" [showFormulaBar]="false"
        (created)="created()" (beforeCellRender)="beforeCellRender($event)">
        <e-sheets>
            <e-sheet name="Order Details" [showGridLines]="false">
                <e-ranges>
                    <e-range [dataSource]="data"></e-range>
                </e-ranges>
                <e-columns>
                    <e-column [width]="80"></e-column>
                    <e-column [width]="130"></e-column>
                    <e-column [width]="180"></e-column>
                    <e-column [width]="90"></e-column>
                    <e-column [width]="160"></e-column>
                    <e-column [width]="80"></e-column>
                    <e-column [width]="100"></e-column>
                    <e-column [width]="130"></e-column>
                    <e-column [width]="80"></e-column>
                </e-columns>
            </e-sheet>
        </e-sheets>
    </ejs-spreadsheet>
</div>
```

### src/components/spreadsheet-editor-cell-formatting/spreadsheet-editor.component.ts

```typescript
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { SpreadsheetComponent, SpreadsheetModule } from '@syncfusion/ej2-angular-spreadsheet';
import { CellRenderEventArgs } from '@syncfusion/ej2-angular-spreadsheet';
import { orderDetails } from '../datasource/spreadsheet-editor-data';
/**
 * Cell Formatting Spreadsheet Component
 */
@Component({
    selector: 'control-content',
    templateUrl: 'spreadsheet-editor.component.html',
    encapsulation: ViewEncapsulation.None,
    standalone: true,
    imports: [SpreadsheetModule]
})

export class CellFormattingController {
    @ViewChild('cellFormat')
    public spreadsheetObj!: SpreadsheetComponent;
    public data: Object[] = orderDetails();
    created() {
        // Temporarily suspends UI rendering to batch model updates for better performance.
        this.spreadsheetObj.suspendRefresh();
        //Applying cell formatting dynamically using cellFormat method.
        this.spreadsheetObj.cellFormat({ fontWeight: 'bold', backgroundColor: '#4b5366', color: '#ffffff', fontSize: '12pt' }, 'A1:J1');
        this.spreadsheetObj.cellFormat({ fontWeight: 'bold', textIndent: '2pt' }, 'B2:B16');
        this.spreadsheetObj.cellFormat({ fontStyle: 'italic', textIndent: '2pt' }, 'E2:E16');
        this.spreadsheetObj.cellFormat({ textIndent: '2pt' }, 'F1:F16');
        this.spreadsheetObj.cellFormat({ textIndent: '2pt' }, 'G1:G16');
        this.spreadsheetObj.cellFormat({ textAlign: 'center', fontWeight: 'bold' }, 'I2:I16');
        this.spreadsheetObj.cellFormat({ fontFamily: 'Helvetica New', verticalAlign: 'middle' }, 'A1:J16');
        //Applying border to a range
        this.spreadsheetObj.setBorder({ border: '1px solid #e0e0e0' }, 'A1:J16', 'Outer');
        this.spreadsheetObj.setBorder({ border: '1px solid #e0e0e0' }, 'A2:J15', 'Horizontal');
        // Applying a short date format to a range.
        this.spreadsheetObj.numberFormat('m/d/yyyy', 'D2:D16');
        // Applying currency format to a range.
        this.spreadsheetObj.numberFormat('$#,##0.00', 'J2:J16');
        // Applying subscript and superscript format.
        this.spreadsheetObj.updateCell({ richText: [
                { text: 'Mineral Water H' },
                { text: '2', style: { verticalAlign: 'sub' } },
                { text: 'O' }
            ] }, 'C2');
        this.spreadsheetObj.updateCell({ richText: [
                { text: 'Energy Supplement C' },
                { text: '6', style: { verticalAlign: 'sub' } },
                { text: 'H' },
                { text: '12', style: { verticalAlign: 'sub' } },
                { text: 'O' },
                { text: '6', style: { verticalAlign: 'sub' } }
            ] }, 'C4');
        this.spreadsheetObj.updateCell({ richText: [
                { text: 'Refrigerant Gas CO' },
                { text: '2', style: { verticalAlign: 'sub' } }
            ] }, 'C6');
        this.spreadsheetObj.updateCell({ richText: [
                { text: 'Water Purifier H' },
                { text: '2', style: { verticalAlign: 'sub' } },
                { text: 'O System' }
            ] }, 'C10');
        this.spreadsheetObj.updateCell({ richText: [
                { text: 'n' },
                { text: 'o', style: { verticalAlign: 'super' } },
                { text: ' 59 rue de l Abbaye' }
            ] }, 'E2');
        this.spreadsheetObj.updateCell({ richText: [
                { text: '2' },
                { text: 'e', style: { verticalAlign: 'super' } },
                { text: ' rue du Commerce' }
            ] }, 'E5');
        this.spreadsheetObj.updateCell({ richText: [
                { text: '22' },
                { text: 'nd', style: { verticalAlign: 'super' } },
                { text: ' Carrera con Ave. Carlos Soublette' }
            ] }, 'E7');
        this.spreadsheetObj.updateCell({ richText: [
                { text: '2' },
                { text: 'o', style: { verticalAlign: 'super' } },
                { text: ' Calle del Rosal' }
            ] }, 'E9');
        this.spreadsheetObj.updateCell({ richText: [
                { text: '3' },
                { text: 'rd', style: { verticalAlign: 'super' } },
                { text: ' 55 Grizzly Peak Rd.' }
            ] }, 'E11');
        this.spreadsheetObj.updateCell({ richText: [
                { text: '5' },
                { text: 'th', style: { verticalAlign: 'super' } },
                { text: ' 2817 Milton Dr.' }
            ] }, 'E13');
        this.spreadsheetObj.updateCell({ richText: [
                { text: 'Kirchgasse 6' }
            ] }, 'E15');
        // Resume UI rendering after batch model updates.
        this.spreadsheetObj.resumeRefresh();
    }

    beforeCellRender(args: CellRenderEventArgs) {
        // Prevents the cell formatting to be applied to the headers.
        if (args.address.includes('1')) {
            args.element.classList.add('e-header-cell');
        }
    }
}
```
