# Cell Formatting

The Kendo UI for Vue Spreadsheet lets users and developers control how the cells look. You can apply number formats, fonts, colors, alignment, borders, text wrapping, and merged cells through the [toolbar](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/toolbar), the JSON data of the sheets, or the [methods](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/methods) of a range.

[Demo Source](https://demos.telerik.com/kendo-vue-ui/spreadsheet/formatting/source.txt)

## Formatting Through the Toolbar

The default toolbar groups the formatting tools in the following tabs:

| Tab        | Tools                                                                                                                                    |
| :--------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
| **Home**   | Font, font size, **Bold**, **Italic**, **Underline**, text color, background, borders, horizontal and vertical alignment, and text wrap. |
| **Format** | The number format, **Decrease decimal**, **Increase decimal**, and **Clean formatting**.                                                 |
| **View**   | **Merge cells**, which is next to the tools for freezing panes and toggling the grid lines.                                              |

The borders tool offers all borders, inside borders (all, horizontal, or vertical), outside borders, left, top, right, and bottom borders, and no borders. The merge tool offers merging all cells, merging horizontally, merging vertically, and unmerging.

## Number Formats

The **Format** tool of the toolbar changes how the value of a cell is displayed without changing the value itself. The tool offers the following predefined formats:

| Name      | Format code                                                |
| :-------- | :--------------------------------------------------------- |
| Automatic | Removes the format.                                        |
| Text      | `@`                                                        |
| Number    | `#,0.00`                                                   |
| Percent   | `0.00%`                                                    |
| Financial | `_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)` |
| Currency  | `$#,##0.00;[Red]$#,##0.00`                                 |
| Date      | `m/d/yyyy`                                                 |
| Time      | `h:mm:ss AM/PM`                                            |
| Date time | `m/d/yyyy h:mm`                                            |
| Duration  | `[h]:mm:ss`                                                |

The **Increase decimal** and **Decrease decimal** tools add or remove a decimal place of the current format.

You are not limited to the predefined formats. Set any Excel-style format code through the `format` field of a cell or the `format()` method of a range:

```js
// In the JSON data.
{ value: 5400.5, format: '$#,##0.00' }
{ value: 45672, format: 'mmm d, yyyy' } // Dates are stored as serial numbers, as in Excel.

// From code.
spreadsheetRef.value.activeSheet().range('C3:C6').format('0.00%');
```

> tip To translate the names of the predefined formats in the **Format** tool, use the `spreadsheet.formatAutomatic`, `spreadsheet.formatText`, `spreadsheet.formatNumber`, `spreadsheet.formatPercent`, `spreadsheet.formatFinancial`, `spreadsheet.formatCurrency`, `spreadsheet.formatDate`, `spreadsheet.formatTime`, `spreadsheet.formatDateTime`, and `spreadsheet.formatDuration` [globalization messages](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/globalization). The format codes stay the same.

## Formatting Through JSON Data

Set the formatting of a cell through its fields when you define the sheets:

| Field                                                        | Description                                                                            |
| :----------------------------------------------------------- | :------------------------------------------------------------------------------------- |
| `format`                                                     | The number format code of the cell.                                                    |
| `fontFamily` and `fontSize`                                  | The font and the font size of the text.                                                |
| `bold`, `italic`, and `underline`                            | Set to `true` to apply the corresponding font style.                                   |
| `color` and `background`                                     | The text color and the background color, for example `'rgb(0,62,117)'` or `'#003e75'`. |
| `textAlign`                                                  | The horizontal alignment—`'left'`, `'center'`, `'right'`, or `'justify'`.              |
| `verticalAlign`                                              | The vertical alignment—`'top'`, `'center'`, or `'bottom'`.                             |
| `wrap`                                                       | Set to `true` to wrap long text in multiple lines.                                     |
| `indent`                                                     | The indentation of the text.                                                           |
| `borderTop`, `borderRight`, `borderBottom`, and `borderLeft` | The borders of the cell, defined as `{ size: 1, color: '#000000' }`.                   |

The merged cells are defined at the level of the sheet through the `mergedCells` field:

```js
const sheets = [
    {
        name: 'Sales',
        mergedCells: ['A1:E1'],
        rows: [
            {
                height: 36,
                cells: [
                    {
                        value: 'Quarterly sales report',
                        bold: true,
                        fontSize: 18,
                        textAlign: 'center',
                        verticalAlign: 'center',
                        color: 'rgb(0,62,117)'
                    }
                ]
            },
            {
                cells: [
                    { value: 'Chai', bold: true, borderBottom: { size: 1, color: 'rgb(0,62,117)' } },
                    { value: 0.12, format: '0.00%', textAlign: 'center' }
                ]
            }
        ]
    }
];
```

## Formatting Through Code

Use the methods of a range to read or change the formatting at runtime. The setter methods return the range, so you can chain the calls:

```js
const sheet = spreadsheetRef.value.activeSheet();

sheet.range('A1:E1').background('rgb(0,62,117)').color('rgb(255,255,255)').bold(true);
sheet.range('B3:B6').textAlign('center');
sheet.range('E3').wrap(true);
sheet.range('A1:E1').merge();

sheet.range('A1').bold(); // Returns the current value.
sheet.range('A1:E1').unmerge();
sheet.range('A3:E6').clearFormat(); // Removes the formatting but keeps the values.
```

For the full list of the range methods, see [Methods of the Spreadsheet](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/methods).

## Suggested Links

* [Toolbar of the Spreadsheet](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/toolbar)
* [Methods of the Spreadsheet](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/methods)
* [Hyperlinks, Comments, and Images in the Spreadsheet](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/hyperlinks-comments-images)
* [Globalization of the Spreadsheet](https://www.telerik.com/kendo-vue-ui-develop/components/spreadsheet/globalization)
