# spreadsheet-editor-cell-formatting

> Spreadsheet editor with cell formatting feature by applying different styles to a range of cells.

**Framework:** vue  **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/vue/spreadsheet-editor-cell-formatting.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-vue-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.vue

```vue
<template>
  <div class="control-section">
    <div id="spreadsheet-cell-format">
      <ejs-spreadsheet ref="spreadsheet" :showRibbon="false" :showFormulaBar="false" :created="createdHandler" :beforeCellRender="beforeCellRender">
        <e-sheets>
          <e-sheet name="Order Details" :showGridLines="false">
            <e-ranges>
              <e-range :dataSource="orderDetails"></e-range>
            </e-ranges>
            <e-columns>
              <e-column :width="70"></e-column>
              <e-column :width="126"></e-column>
              <e-column :width="172"></e-column>
              <e-column :width="90"></e-column>
              <e-column :width="238"></e-column>
              <e-column :width="82"></e-column>
              <e-column :width="80"></e-column>
              <e-column :width="249"></e-column>
            </e-columns>
          </e-sheet>
        </e-sheets>
      </ejs-spreadsheet>
    </div>
  </div>
</template>
<script>
import { SpreadsheetComponent, SheetsDirective, SheetDirective, ColumnsDirective, ColumnDirective, RangesDirective, RangeDirective, getFormatFromType } from "@syncfusion/ej2-vue-spreadsheet";
import { orderDetails } from '../datasource/spreadsheet-editor-data';

export default {
   components: {
    'ejs-spreadsheet': SpreadsheetComponent,
    'e-sheet': SheetDirective,
    'e-sheets': SheetsDirective,
    'e-column': ColumnDirective,
    'e-columns': ColumnsDirective,
    'e-range': RangeDirective,
    'e-ranges': RangesDirective
   }, 
   data: () => {
      return {
          orderDetails: orderDetails
      }
  },
  methods: {
    createdHandler: function() {
        // Temporarily suspends UI rendering to batch model updates for better performance.
        this.$refs.spreadsheet.suspendRefresh();
        //Applying cell formatting dynamically using cellFormat method.
        this.$refs.spreadsheet.cellFormat({ fontWeight: 'bold', backgroundColor: '#4b5366', color: '#ffffff', fontSize: '12pt' }, 'A1:I1');
        this.$refs.spreadsheet.cellFormat({ fontWeight: 'bold', textIndent: '2pt' }, 'B2:B16');
        this.$refs.spreadsheet.cellFormat({ fontStyle: 'italic', textIndent: '2pt' }, 'E2:E16');
        this.$refs.spreadsheet.cellFormat({ textAlign: 'center', fontWeight: 'bold' }, 'G2:G16');
        this.$refs.spreadsheet.cellFormat({ textAlign: 'center'}, 'H2:H16');
        this.$refs.spreadsheet.cellFormat({ fontFamily: 'Helvetica New', verticalAlign: 'middle' }, 'A1:I16');
        //Applying border to a range
        this.$refs.spreadsheet.setBorder({ border: '1px solid #e0e0e0' }, 'A1:I16', 'Outer');
        this.$refs.spreadsheet.setBorder({ border: '1px solid #e0e0e0' }, 'A2:I15', 'Horizontal');
        // Applying a short date format to a range.
        this.$refs.spreadsheet.numberFormat('m/d/yyyy', 'D2:D16');
        // Applying currency format to a range.
        this.$refs.spreadsheet.numberFormat('$#,##0.00', 'I2:I16');
        // Applying subscript and superscript format.
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Mineral Water H' },
                { text: '2', style: { verticalAlign: 'sub' } },
                { text: 'O' }
            ] }, 'C2');
        this.$refs.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');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Refrigerant Gas CO' },
                { text: '2', style: { verticalAlign: 'sub' } }
            ] }, 'C6');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Water Purifier H' },
                { text: '2', style: { verticalAlign: 'sub' } },
                { text: 'O System' }
            ] }, 'C10');
        // Address formatting with maintained superscript for ordinals
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'n' },
                { text: 'o', style: { verticalAlign: 'super' } },
                { text: ' 59 rue de l Abbaye' },
                { text: ', Reims 51100' }
            ] }, 'E2');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: '2' },
                { text: 'e', style: { verticalAlign: 'super' } },
                { text: ' rue du Commerce' },
                { text: ', Lyon 69004'}
            ] }, 'E5');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: '6' },
                { text: 'th', style: { verticalAlign: 'super' } },
                { text: ' street, Kirchgasse' },
                { text: ', Graz 8010'}
            ] }, 'E7');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: '22' },
                { text: 'nd', style: { verticalAlign: 'super' } },
                { text: ' Carrera con Ave. Carlos Soublette' },
                { text: ', San Cristóbal 5022'}
            ] }, 'E11');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: '101 4' },
                { text: 'th', style: { verticalAlign: 'super' } },
                { text: ' Street, San Francisco' },
                { text: ', Albuquerque 87110'}
            ] }, 'E16');
        // Order Notes rich text formatting with styled pipe separator
        this.$refs.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');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Packed Securely', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Customer Confirmed', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H3');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Tracking Active', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Express Delivery', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H4');
        this.$refs.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');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Shipment Processed', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Route Confirmed', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H6');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Return Requested', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Refund Approved', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H7');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Awaiting Dispatch', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Inventory Reserved', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H8');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Quality Checked', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Signature Required', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H9');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Tracking Active', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Scheduled Delivery', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H10');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Package Delivered', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Customer Verified', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H11');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Refund Initiated', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Case Closed', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H12');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Awaiting Processing', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Stock Allocation', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H13');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Inspection Passed', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Customer Approved', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H14');
        this.$refs.spreadsheet.updateCell({ richText: [
                { text: 'Order Packed', style: { fontWeight: 'bold', color: '#1F4E79' } },
                { text: ' | ', style: { color: '#808080' } },
                { text: 'Carrier Assigned', style: { fontStyle: 'italic', color: '#2E8B57' } }
            ] }, 'H15');
        this.$refs.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.
        this.$refs.spreadsheet.resumeRefresh();
    },
    beforeCellRender: function(args) {
       if (this.applyCellFormat()) {
            if (args.cell && args.cell.value) {
                //Applying cell formatting before rendering the particular cell
                switch (args.cell.value) {
                    case 'Delivered':
                        this.$refs.spreadsheet.cellFormat({ color: '#10c469', textDecoration: 'line-through' }, args.address);
                        break;
                    case 'Shipped':
                        this.$refs.spreadsheet.cellFormat({ color: '#62c9e8' }, args.address);
                        break;
                    case 'Pending':
                        this.$refs.spreadsheet.cellFormat({ color: '#FFC107', textDecoration: 'underline' }, args.address);
                        break;
                    case 'Cancelled':
                        this.$refs.spreadsheet.cellFormat({ color: '#ff5b5b' }, args.address);
                        break;
                }
            }
      }
    },
    applyCellFormat: function() {
      return !this.$refs.spreadsheet.ej2Instances.isOpen && this.$refs.spreadsheet.ej2Instances.sheets[this.$refs.spreadsheet.ej2Instances.activeSheetIndex].name === 'Order Details';
    }
  }
}
</script>
```
