# spreadsheet-editor-cell-formatting

> Spreadsheet editor with cell formatting feature by applying different styles to a range of cells.

**Framework:** react  **Component:** SpreadsheetEditor  **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/react/ts/spreadsheet-editor-cell-formatting.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-react-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/SpreadSheetEditor.tsx

```tsx
import React from 'react';
import { SpreadsheetComponent, type SheetModel, type RowModel, type CellRenderEventArgs } from '@syncfusion/ej2-react-spreadsheet';
import { orderDetails } from '../datasource/spreadsheet-editor.data';
import '../spreadsheet-editor.css';

/**
 * Cell Formatting sample
 */

function CellFormatting(): React.ReactElement {
    let spreadsheet: SpreadsheetComponent;

    // Define rows with initial cell formatting
    const rows: RowModel[] = [
        {
            height: 36,
            // Applying cell formatting through cell binding
            cells: [
                { style: { textAlign: 'right' } },
                { style: { textIndent: '2pt' } },
                { style: { textAlign: 'center' } },
                { style: { textAlign: 'right' } },
                { style: { textIndent: '2pt' } },
                { index: 6, style: { textAlign: 'center' } },
                { index: 7, style: { textAlign: 'center' } },
                { index: 8, style: { textAlign: 'right' } }
            ]
        },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 },
        { height: 42 }
    ];

    const sheetSettings: SheetModel[] = [
        {
            name: 'Order Details',
            ranges: [{ dataSource: orderDetails }],
            columns: [
                { width: 70 },
                { width: 126 },
                { width: 172 },
                { width: 90 },
                { width: 238 },
                { width: 82 },
                { width: 80 },
                { width: 249 }
            ],
            rows: rows,
            showGridLines: false
        }
    ];

    function createdHandler(): void {
        // Temporarily suspends UI rendering to batch model updates for better performance.
        spreadsheet.suspendRefresh();

        // Applying cell formatting dynamically using cellFormat method.
        spreadsheet.cellFormat({ fontWeight: 'bold', backgroundColor: '#4b5366', color: '#ffffff', fontSize: '12pt' }, 'A1:I1');
        spreadsheet.cellFormat({ fontWeight: 'bold', textIndent: '2pt' }, 'B2:B16');
        spreadsheet.cellFormat({ fontStyle: 'italic', textIndent: '2pt' }, 'E2:E16');
        spreadsheet.cellFormat({ textAlign: 'center', fontWeight: 'bold' }, 'G2:G16');
        spreadsheet.cellFormat({ textAlign: 'center' }, 'H2:H16');
        spreadsheet.cellFormat({ fontFamily: 'Helvetica New', verticalAlign: 'middle' }, 'A1:I16');

        // Applying border to a range
        spreadsheet.setBorder({ border: '1px solid #e0e0e0' }, 'A1:I16', 'Outer');
        spreadsheet.setBorder({ border: '1px solid #e0e0e0' }, 'A2:I15', 'Horizontal');

        // Applying a short date format to a range.
        spreadsheet.numberFormat('m/d/yyyy', 'D2:D16');

        // Applying currency format to a range.
        spreadsheet.numberFormat('$#,##0.00', 'I2:I16');

        // Applying subscript and superscript format.
        spreadsheet.updateCell({ richText: [
            { text: 'Mineral Water H' },
            { text: '2', style: { verticalAlign: 'sub' } },
            { text: 'O' }
        ] }, 'C2');

        spreadsheet.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');

        spreadsheet.updateCell({ richText: [
            { text: 'Refrigerant Gas CO' },
            { text: '2', style: { verticalAlign: 'sub' } }
        ] }, 'C6');

        spreadsheet.updateCell({ richText: [
            { text: 'Water Purifier H' },
            { text: '2', style: { verticalAlign: 'sub' } },
            { text: 'O System' }
        ] }, 'C10');

        spreadsheet.updateCell({ richText: [
            { text: 'n' },
            { text: 'o', style: { verticalAlign: 'super' } },
            { text: ' 59 rue de l Abbaye' },
            { text: ', Reims 51100' }
        ] }, 'E2');

        spreadsheet.updateCell({ richText: [
            { text: '2' },
            { text: 'e', style: { verticalAlign: 'super' } },
            { text: ' rue du Commerce' },
            { text: ', Lyon 69004' }
        ] }, 'E5');

        spreadsheet.updateCell({ richText: [
            { text: '6' },
            { text: 'th', style: { verticalAlign: 'super' } },
            { text: ' street, Kirchgasse' },
            { text: ', Graz 8010' }
        ] }, 'E7');

        spreadsheet.updateCell({ richText: [
            { text: '22' },
            { text: 'nd', style: { verticalAlign: 'super' } },
            { text: ' Carrera con Ave. Carlos Soublette' },
            { text: ', San Cristóbal 5022' }
        ] }, 'E11');

        spreadsheet.updateCell({ richText: [
            { text: '101 4' },
            { text: 'th', style: { verticalAlign: 'super' } },
            { text: ' Street, San Francisco' },
            { text: ', Albuquerque 87110' }
        ] }, 'E16');

        spreadsheet.updateCell({ richText: [
            { text: 'Quality Checked', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Signed by Customer', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H2');

        spreadsheet.updateCell({ richText: [
            { text: 'Packed Securely', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Customer Confirmed', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H3');

        spreadsheet.updateCell({ richText: [
            { text: 'Tracking Active', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Express Delivery', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H4');

        spreadsheet.updateCell({ richText: [
            { text: 'Delivery Verified', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Received On Time', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H5');

        spreadsheet.updateCell({ richText: [
            { text: 'Shipment Processed', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Route Confirmed', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H6');

        spreadsheet.updateCell({ richText: [
            { text: 'Return Requested', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Refund Approved', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H7');

        spreadsheet.updateCell({ richText: [
            { text: 'Awaiting Dispatch', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Inventory Reserved', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H8');

        spreadsheet.updateCell({ richText: [
            { text: 'Quality Checked', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Signature Required', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H9');

        spreadsheet.updateCell({ richText: [
            { text: 'Tracking Active', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Scheduled Delivery', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H10');

        spreadsheet.updateCell({ richText: [
            { text: 'Package Delivered', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Customer Verified', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H11');

        spreadsheet.updateCell({ richText: [
            { text: 'Refund Initiated', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Case Closed', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H12');

        spreadsheet.updateCell({ richText: [
            { text: 'Awaiting Processing', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Stock Allocation', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H13');

        spreadsheet.updateCell({ richText: [
            { text: 'Inspection Passed', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Customer Approved', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H14');

        spreadsheet.updateCell({ richText: [
            { text: 'Order Packed', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Carrier Assigned', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H15');

        spreadsheet.updateCell({ richText: [
            { text: 'Delivered Successfully', style: { fontWeight: 'bold', color: '#1F4E79' } },
            { text: ' | ', style: { color: '#808080' } },
            { text: 'Signature Captured', style: { fontStyle: 'italic', color: '#2E8B57' } }
        ] }, 'H16');

        // Resumes rendering and applies all queued UI updates at once.
        spreadsheet.resumeRefresh();
    }

    function beforeCellRender(args: CellRenderEventArgs): void {
        if (spreadsheet.sheets[spreadsheet.activeSheetIndex].name === 'Order Details' && !spreadsheet.isOpen) {
            if (args.cell && args.cell.value) {
                // Applying cell formatting before rendering the particular cell.
                switch (args.cell.value) {
                    case 'Delivered':
                        spreadsheet.cellFormat({ color: '#205107', textDecoration: 'line-through' }, args.address);
                        break;
                    case 'Shipped':
                        spreadsheet.cellFormat({ color: '#01579B' }, args.address);
                        break;
                    case 'Pending':
                        spreadsheet.cellFormat({ color: '#914C00', textDecoration: 'underline' }, args.address);
                        break;
                    case 'Cancelled':
                        spreadsheet.cellFormat({ color: '#B3261E' }, args.address);
                        break;
                }
            }
        }
    }

    return (
        <div className='control-pane'>
            <div className='control-section spreadsheet-control'>
                <SpreadsheetComponent showRibbon={false} showFormulaBar={false} sheets={sheetSettings}
                    ref={(ssObj: SpreadsheetComponent | null) => { if (ssObj) spreadsheet = ssObj }} created={createdHandler}
                    beforeCellRender={beforeCellRender}>
                </SpreadsheetComponent>
            </div>
        </div>
    );
}

export default CellFormatting;

```
