TX Sheet Control

Formatting and Number Display

Topic

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 of the browser editor:

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 applies a Format patch to the whole range.
  • The first call formats the headings in A1:F1: font sets Liberation Sans in size 11 and bold, fill the background #163b63, textColor white text and wrapText wraps the text in the cells.
  • The second call sets numberFormat 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

  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 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. 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. 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

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 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.

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