# Formatting and Number Display

> Format ranges with Range.format or the Format Cells dialog: fonts, fills, wrapping, currency, percentage and date formats, custom codes, styles and rich text.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Spreadsheet Documents > Formatting and Number Display
- **1753 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/formatting/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/formatting/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/formatting/llms-full.txt

---

Formatting changes how a cell looks while it preserves the typed value the cell holds. Format cells in the Home ribbon of the editor or in code through a worksheet-bound range. Number formats decide how stored numbers, currencies, percentages and dates are displayed, without changing the numbers themselves.

### Format a Range in Code

The following code formats the column headings of the first worksheet and displays two columns of amounts as US dollars. `editor` is the [`Spreadsheet`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/llms-full.txt) of the browser editor:

```javascript
const sheet = editor.workbook.sheets.at(0);
sheet.range('A1:F1').format({
    font: { family: 'Liberation Sans', size: 11, bold: true },
    fill: '#163b63', textColor: '#ffffff', wrapText: true
});

sheet.range('E2:F25').format({
    numberFormat: { type: 'currency', currency: 'USD', decimals: 2 }
});
```

The code works as follows:

- [`Range.format`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/range/format-method/llms-full.txt) applies a [`Format`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/format/llms-full.txt) patch to the whole range.
- The first call formats the headings in `A1:F1`: [`font`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/format/font-property/llms-full.txt) sets Liberation Sans in size 11 and bold, [`fill`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/format/fill-property/llms-full.txt) the background `#163b63`, [`textColor`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/format/textcolor-property/llms-full.txt) white text and [`wrapText`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/format/wraptext-property/llms-full.txt) wraps the text in the cells.
- The second call sets [`numberFormat`](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/format/numberformat-property/llms-full.txt) for `E2:F25`: the type `currency`, the currency `USD` and two decimal places.

Unspecified properties retain the existing formatting. Use the documented `null` reset values where supported: an omitted value and an explicit reset are different operations. The `Format` reference lists the grouped font, alignment and number options.

### Format a Selection in the UI

1. Select the range.
2. Open **Format Cells** from a launcher of the Home ribbon or from the context menu of the cell. The **Number** section previews the first cell with the draft display format:

    ![Format Cells with the Number section and a separate Live Preview and Formatted Value](https://docs.textcontrol.com/assets/img/tx-sheet-control/format-cells-number.a8d713bf.webp)
3. For sales totals, choose **Currency**, the appropriate symbol and the displayed decimal places.
4. Open the other sections for alignment, font, borders, fill and protection.
5. Choose **OK** to apply the draft. **Cancel** leaves the cells as they were.

[Format Cells Dialog](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/format-cells/llms-full.txt) explains each section with screenshots.

### Choose a Number Format

General, numeric, currency and accounting, percentage, date and time, scientific, fraction and supported custom format codes control the display. For example, a stored `0.15` displayed as a percentage becomes `15%`, and the number remains `0.15`. Increasing the decimal places does not restore precision that was never stored.

- **Custom codes.** Use `numberFormat.code` for an explicit Excel-style code.
- **Locales.** Use `numberFormat.locale` for a specific display locale.
- **Dates.** Date serials need the date system of the workbook, [`Workbook.dateSystem`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/workbook/datesystem-property/llms-full.txt). A German date display such as `dd.mm.yyyy` is a format choice, not an instruction to parse arbitrary localized text as a date.

### Use Styles, Themes and Rich Text

- **Named cell styles** provide reusable formatting.
- **Workbook theme colors** provide coordinated choices.
- **Tables** have separate native table styles.
- **Rich text** applies formatting to runs within one cell, with [`Cell.setRichText`](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/cell/setrichtext-method/llms-full.txt). Preserve the run boundaries when you change only part of the content.

### Edit a Cell Style

Open **Home → Cell Styles** and choose **New Cell Style…**, or open an existing style for modification. The **Cell Style** dialog shares the six sections and persistent preview of Format Cells. Enter a meaningful **Name**, enable the formatting categories the style should include and configure those categories. Opening one section closes the previous one without resizing the dialog.

![Cell Style with a name, the Font section, an Apply Font switch and a persistent preview](https://docs.textcontrol.com/assets/img/tx-sheet-control/cell-style-dialog.335facff.webp)

The shared preview combines alignment, text orientation, font and fill. In **Border**, use the left-side line style, color and presets and click edges in that preview to edit the style's borders. In **Fill**, choose **Pattern Style**, **Pattern Color** and **Background Color**. Enable **Apply Fill** to include the background and pattern in the saved style; gallery previews show the pattern.

Choose **Save Style** to keep the definition or **Cancel** to discard the draft. Included categories determine what the style supplies; a disabled category is not a request to clear that formatting from every cell. The existing reset and delete commands remain available where they apply to the selected style.

### Deploy Fonts Before AutoFit and Export

Use deployed fonts and await initialization before AutoFit or export. Font metrics affect column widths, wrapping, row heights and pagination.

A supported browser display face is not necessarily sufficient for PDF embedding. [Custom Fonts](https://docs.textcontrol.com/tx-sheet-control/deployment/custom-fonts/llms-full.txt) covers the fonts of the browser editor and of the backend.

### How Conditional Formatting Relates to the Base Style

Review conditional formatting separately from the base style. Calculated rules can change the effective displayed appearance without overwriting the underlying base style.

### Pattern Fills

Apply hatch fills using `fillPattern` and a background `fillColor`. Set `fillPattern` to null to return to a solid fill. Patterns are editable through the cell and range formatting APIs and through the **Fill** section of **Format Cells** and **Cell Style**. They render as clipped vector marks in PDF and round-trip through XLSX, ODS and TXWB. Changing a pattern does not change cell values.

```javascript
const sheet = editor.workbook.sheets.at(0);
sheet.cell('B3').setText('Planned activity');
sheet.cell('B3').format({ fillColor: '#ffffff', fillPattern: { type: 'lightUp', color: '#735773' } });
```

### Next Steps

- [Format Cells Dialog](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/format-cells/llms-full.txt): go through each section of the dialog with screenshots.
- [Conditional Formatting and Cell Styles](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/conditional-formatting/llms-full.txt): add rules that change the appearance with the data and create reusable named styles.
- [Custom Fonts](https://docs.textcontrol.com/tx-sheet-control/deployment/custom-fonts/llms-full.txt): deploy licensed fonts for the browser editor and the backend.
- [Dates and Locales](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/dates/llms-full.txt): keep the stored date, the date system, the format code and the locale apart.

---

## Nearby

- **Previous:** [Copy, Paste and Fill](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/copy-fill/llms-full.txt)
- **Next:** [Conditional Formatting and Cell Styles](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/conditional-formatting/llms-full.txt)
