Birch UI v0.1
Pricing

FormattingSpreadsheet

Cell styles, Excel number format codes, merged cells, frozen panes, column widths and row heights, and conditional formatting with value, text, date and formula rules, colour scales, data bars and icon sets.

Open .md

Formatting changes how values look, never the values themselves. A cell holding 0.0625 with the format 0.00% shows 6.25%, and formulas still see 0.0625.

Cell styles#

A style is a plain object. Set it in the workbook JSON or with setStyle(); users toggle bold, italic, underline and strikethrough with Ctrl + B, Ctrl + I, Ctrl + U and Ctrl + 5.

CellStyleinterface@birchui/spreadsheetFull reference
PropertyTypeDescription
boldoptionalboolean—
italicoptionalboolean—
underlineoptionalboolean—
strikeoptionalboolean—
coloroptionalstring—
fontSizeoptionalnumber—
fontFamilyoptionalstring—
filloptionalstring—
alignoptional'left' | 'center' | 'right'—
valignoptional'top' | 'middle' | 'bottom'—
wrapoptionalboolean—
indentoptionalnumber—
numberFormatoptionalstring—
borderoptionalCellBorders—
lockedoptionalboolean—
hideFormulaoptionalboolean—
rotationoptionalnumber—
shrinkoptionalboolean—
horizontaloptional'fill' | 'justify' | 'centerContinuous' | 'distributed'—
verticaloptional'justify' | 'distributed'—
readingOrderoptional'ltr' | 'rtl'—
underlineStyleoptional'double' | 'singleAccounting' | 'doubleAccounting'—
scriptoptional'superscript' | 'subscript'—
fillPatternoptionalPatternFill—
fillGradientoptionalGradientFill—
colorThemeoptionalThemeColor—
fillThemeoptionalThemeColor—
styleNameoptionalstring—
controloptionalCellControl—
TypeScript
sheet.setStyle('A6:E6', { bold: true, fill: '#1f3a5f', color: '#ffffff', align: 'center' });
sheet.setStyle('B7:E366', { numberFormat: '#,##0.00' });
sheet.setStyle('E366', { border: { top: { style: 'thin' }, bottom: { style: 'double', color: '#1f3a5f' } } });

setStyle(range, style, mode?) merges the properties into each cell's existing style by default. Pass 'replace' as the mode to replace the style completely, or null as the style to clear it. getStyle(address) returns a cell's style.

Property Values
bold, italic, underline, strike true or false.
color, fill CSS hex colours such as '#1f3a5f'. A cell with a light fill and no color is drawn with dark text in every theme, so it stays readable in dark mode; set --lq-sheet-on-light-fill to change that colour.
fontSize, fontFamily Points and a font family name.
align 'left', 'center' or 'right'. Without it, numbers align right and text left, as in Excel.
valign 'top', 'middle' or 'bottom'.
wrap, indent Wrap text in the cell; indent by a number of levels.
numberFormat An Excel format code, see below.
border { top, right, bottom, left, diagonalUp, diagonalDown }, each { style, color }. The styles are thin, medium, thick, dashed, dotted, double, hair, mediumDashed, dashDot, mediumDashDot, dashDotDot, mediumDashDotDot and slantDashDot. diagonalUp runs from the bottom left corner to the top right, diagonalDown from the top left to the bottom right.
rotation Degrees from -90 to 90, counter-clockwise for positive values, or 255 for letters stacked top to bottom.
shrink true to shrink the text until it fits the column.
horizontal, vertical The alignments that have no simple equivalent: horizontal is 'fill', 'justify', 'centerContinuous' or 'distributed'; vertical is 'justify' or 'distributed'. Set align or valign to the nearest simple value next to it, as an imported file does.
readingOrder 'ltr' or 'rtl' for the text direction of one cell.
underlineStyle 'double', 'singleAccounting' or 'doubleAccounting', together with underline: true.
script 'superscript' or 'subscript'.
fillGradient { type: 'linear', degree, stops } or { type: 'path', left, right, top, bottom, stops }, each stop { position, color } with position from 0 to 1. Keep fill equal to the colour of the first stop.
fillPattern { pattern, color, background } with one of Excel's 17 patterns, such as 'lightUp' or 'darkGrid'. Keep fill equal to color.
colorTheme, fillTheme { theme, tint? }: the theme colour the color or fill came from. Border sides and gradient stops take colorTheme too.
styleName The name of a named cell style in the workbook's cellStyles, such as 'Good'. The cell still carries the style's formatting itself.

The properties from rotation down come from Excel files and are written back to them; see What round-trips. fill, align and valign always hold a plain fallback value next to the exact one.

The fallback and the exact value belong together. When a style change gives the fallback a new value, the exact value is removed, so the cell and the exported file show what was just chosen:

Changing Removes
fill fillGradient, fillPattern, fillTheme
color colorTheme
align horizontal
valign vertical
the color of a border side that side's colorTheme

This applies to setStyle() in merge mode, the ribbon and the Format Cells dialog. To set an exact value from code, pass it together with its fallback in the same call: setStyle('A1', { align: 'center', horizontal: 'centerContinuous' }).

How the grid draws them#

The grid, getPrintHtml() and print() draw the same formatting.

  • Rotation. Positive angles turn the text counter-clockwise, negative angles clockwise, and 255 stacks the letters. A row without a set height grows to fit rotated text and fonts larger than 11 pt. That automatic height is not written to rowHeights; a row with a set height keeps it.
  • Shrink to fit reduces the font size until the text fits the column, down to 35% of the original size. It has no effect on a cell with wrap.
  • Indent is 9 pixels per level, on the side the text is aligned to: the left by default, the right for align: 'right', and both sides for horizontal: 'distributed'.
  • horizontal. fill repeats the text across the cell. justify and distributed wrap the text and spread it over the cell width. centerContinuous (Center across selection) centres the text over the cell and the empty cells to its right that carry the same alignment.
  • vertical justify and distributed are kept and exported, and drawn with the valign fallback.
  • Underlines. double draws a double line. The accounting styles draw the line lower under the text; they do not span the full cell width.
  • Gradients. A linear gradient uses Excel's angle: 0 runs left to right, 90 top to bottom. A path gradient is drawn as a radial gradient centred on the rectangle given by left, right, top and bottom, which approximates Excel's rectangular shape.
  • Patterns. Each of the 17 patterns is drawn as a small repeating tile in the pattern color over the background colour.
  • Borders. All 13 line styles look different. Diagonal borders run corner to corner as solid lines in the width of the style; double draws two lines. Dash patterns are not applied to diagonals.
  • Theme colours are drawn with the RGB value in color, fill or the border side.
  • Text colour on fills. The automatic dark text on light fills uses the average colour of a gradient and the background colour of a pattern.

Rich text#

A cell whose text mixes formats has richText next to its value: a list of runs, each { text, bold?, italic?, underline?, strike?, color?, fontSize?, fontFamily?, script? }. The value is the text of all runs joined.

TypeScript
sheet.fromJSON({
  version: 1,
  sheets: [
    {
      name: 'Summary',
      cells: {
        A1: {
          value: 'Net revenue (unaudited)',
          richText: [
            { text: 'Net ', bold: true },
            { text: 'revenue', italic: true, color: '#c00000' },
            { text: ' (unaudited)', fontSize: 9 },
          ],
        },
      },
    },
  ],
});

The grid draws each run with its own font, colour, underline and superscript or subscript.

To format part of a cell, edit it (F2 or a double-click), select some of the text and press Ctrl + B, Ctrl + I, Ctrl + U or Ctrl + 5, or use the bold, italic, underline, strikethrough, superscript, subscript and text colour buttons and the font and font size lists of the toolbar. A shortcut pressed again on text that already has the format removes it, and with nothing selected it sets the format for what you type next. The editor shows the formats as you work, in the cell and in the formula bar, and committing stores the runs as one undo step. From code, formatEditorSelection({ bold?, italic?, underline?, strike?, color?, fontFamily?, fontSize?, script? }) formats the selection of the open editor and returns false when there is none; null for color, fontFamily, fontSize or script removes it, and script is 'superscript' or 'subscript'.

  • Text typed inside a run takes that run's format, and runs the edit does not touch keep theirs, including the font size, font and superscript or subscript of runs read from a file.
  • Superscript and subscript have no keyboard shortcut; reach the buttons with the ribbon's key tips.
  • Formulas, numbers and dates are never rich text: while one is being edited, the same commands format the whole cell.
  • A cell whose runs carry no format is stored as a plain value, without richText.
  • The toolbar buttons and lists show the format of the cell, not of the selection in the editor, except the superscript and subscript buttons, which follow the selection.

Committing an edit without changing the text keeps the runs, and so does setStyle(). Replacing the text by pasting, filling or setValue() turns the cell into plain text, and undo brings the runs back. Setting a formula on the cell removes the runs. Runs are kept in the workbook JSON and are read from and written to Excel files. If value no longer equals the joined runs, the file gets the plain value.

Cell controls#

A cell can carry a control, stored in its style as control.

TypeScript
sheet.setRange('A1:B4', [
  ['Task', 'Done'],
  ['Draft the budget', true],
  ['Send invoices', false],
  ['Book the venue', null],
]);
sheet.setCellControl('B2:B4', 'checkbox');
sheet.setFormula('B5', '=COUNTIF(B2:B4,TRUE)');

sheet.addValidation({ range: 'C2:C4', type: 'list', values: ['North', 'South', 'West'] });
sheet.setCellControl('C2:C4', 'dropdown');

sheet.getCellControl('B2'); // 'checkbox'
sheet.setCellControl('B2:B4', null);

Checkbox. A cell with the checkbox control draws a box for TRUE and FALSE; a blank cell counts as unchecked. Any other value is shown as text, without a box. The value stays a real boolean, so formulas such as COUNTIF(B2:B4,TRUE) work on it. A click on the box toggles it. Space toggles every checkbox in the selection to the opposite of the active cell. Toggling is an ordinary edit: it is refused in read-only mode and on locked cells of a protected sheet, it goes through data validation, it fires cellChange and it can be undone. A cell whose boolean comes from a formula shows the box and does not toggle. Insert > Checkbox turns the control on or off for the selection.

Screen readers hear the state in the cell's name, for example "B4, checked, checkbox", and each toggle is announced. The box follows the theme, right-to-left layout and zoom. It is printed as a box with a tick, and the PDF export draws it as lines.

Dropdown. A cell with the dropdown control and a list validation shows its arrow all the time, not only while it is selected. The arrow sits at the right edge of the cell, the left edge in right-to-left sheets and cells, and the cell keeps that strip free, so text and right-aligned numbers never run under it. A click on the arrow, Alt + Arrow Down or F4 opens the list. The items are drawn as plain text. Without a list validation on the cell the control does nothing and no arrow is drawn.

Both controls travel with the cell style: copy and paste, fill, undo, toJSON() and collaboration operations carry them. In xlsx files:

Import Export
Checkbox Excel's in-cell checkboxes are read as the checkbox control. Plain TRUE and FALSE values by default, listed in the export report as "Checkboxes written as TRUE/FALSE". exportXlsx({ checkboxes: 'excel' }) writes Excel's checkbox structure (the feature property bag part and the cell format extension). That mode passes our own reader and the package validator, but we could not open the result in Excel, so treat it as unverified.
Dropdown The list validation is read. The always-visible arrow is not a file feature. The list validation is written. The dropdown control is not stored and is listed in the export report.

The button and announcement texts of the controls are in English in every locale for now.

Number formats#

numberFormat takes the same format codes as Excel's Format Cells › Custom dialog. Typing values such as 6.25%, $1,250 or 3/15/2026 sets a matching format automatically.

Code Value Shows
General 1234.5 1234.5
#,##0.00 1234.567 1,234.57
$#,##0.00 1539.293 $1,539.29
0.00% 0.0625 6.25%
#,##0.00;[Red](#,##0.00) -1234.5 (1,234.50) in red
#,##0;-#,##0;"-" 0 -
#,##0,"K" 1234567 1,235K
0.0,,"M" 1234567 1.2M
0.00E+00 12345 1.23E+04
# ?/? 0.75 3/4
[>=100]"High";"Low" 150 High
@" Ltd" Acme Acme Ltd
yyyy-mm-dd 46096 2026-03-15
dddd, d mmmm yyyy 46096 Sunday, 15 March 2026
h:mm AM/PM 46096.75 6:00 PM
[h]:mm 1.5 36:00

Supported features include up to four sections (positive, negative, zero and text), conditions in brackets, the colours [Black], [Blue], [Cyan], [Green], [Magenta], [Red], [White] and [Yellow], thousands separators and scaling with trailing commas, fractions, scientific notation, literal text in quotes, dates, times and elapsed time. Month and day names are in English.

Numbers wider than their column#

A number never runs into the cell beside it and is never cut off.

  • With the General format, the decimals are rounded until the text fits the column: 196833.33333 in a narrow column shows 196833.3 or 196833. The value in the cell does not change. When even the whole part is too wide, the number switches to scientific notation (1.2E+11), and to number signs when that does not fit either.
  • With any other number format, including dates, the cell fills with number signs (####) when the formatted text does not fit, as in Excel. Widen the column or use AutoFit to see the value.
  • The width is measured with the font of the cell: its family, size, bold and italic, at any zoom. Digits are measured as the widest digit, so a column of numbers rounds the same way from row to row.
  • Print output and PDF export follow the same rule with the metrics of the font they use, so a number may round differently on paper than on screen.
  • Cells with wrap or shrink are left alone, and text is never replaced by number signs.

Where the browser offers no canvas to measure with, as in server-side rendering and most test environments, widths are estimated from the character count.

The formatter is exported for use outside the grid, for example to show the same text in a summary card:

TypeScript
import { formatKind, formatValue } from '@birchui/spreadsheet';

formatValue(-1234.5, '#,##0.00;[Red](#,##0.00)');
formatKind('$#,##0.00');

The first call returns { text: '(1,234.50)', color: '#FF0000' } and the second 'currency'. isDateFormat(code) tells you whether a code formats dates or times. getDisplayText(address) returns a cell's formatted text as the grid shows it.

Merged cells#

TypeScript
sheet.mergeCells('A1:E1');
sheet.unmergeCells('A1:E1');

Merging keeps the value and style of the top-left cell and clears the others; a merge that overlaps existing merges replaces them. Merges are stored in the sheet's merges list, such as ['A1:E1'], and saved to xlsx. Users merge and unmerge from the cell menu.

A range that covers only part of a merged cell is treated as covering all of it, as in Excel: Delete clears the merged cell, formats and borders apply to the whole merged cell, and whole rows or columns stay within their own row or column. Filling (the fill handle, Ctrl + D, Ctrl + R) across a merged cell is refused with an error event; unmerge first.

Frozen panes#

TypeScript
sheet.setFreeze(6, 1);
sheet.setFreeze(0, 0);

setFreeze(rows, columns) keeps the first rows and columns of the active sheet in place while scrolling: here the header block and the month column of the loan schedule. 0, 0 unfreezes. In the workbook JSON it is freeze: { rows: 6, columns: 1 }. Users freeze at the selection from the cell menu.

Column widths and row heights#

Widths and heights are in pixels. Users drag the header borders; in code:

TypeScript
sheet.setColumnWidth('B', 140);
sheet.setColumnWidth(5, 160);
sheet.setRowHeight(6, 28);

Columns are given by letter or by 1-based number, rows by 1-based number. The defaults are 88 pixels and 22 pixels, configurable with the defaultColumnWidth and defaultRowHeight options. In the JSON, columnWidths is keyed by column letter and rowHeights by row number. Rows and columns can be hidden and shown from the header menu, and hidden ones are listed in hiddenRows and hiddenColumns.

Set gridlines: false to hide the cell gridlines, which suits form-like sheets.

Double-click the border below a row header, or choose Home > Format > AutoFit row height, to fit a row to its contents. Double-click the border right of a column header, or choose AutoFit column width, to fit a column. Both measure what each cell displays, in its own font: the family, size, bold and italic, including the bold header of a table and formats applied by conditional formatting, together with rotation, indent, rich text and wrapped lines. A column also leaves room for a filter button in a header cell (on both sides when the header is centred), for the arrow of a dropdown control, and for a checkbox or a conditional-format icon. A cell with shrink does not widen its column, and merged cells are skipped. Only the first 5,000 rows are measured.

Conditional formatting#

Conditional formats style cells by their value. Add rules with addConditionalFormat(rule, sheet?) or in a sheet's conditionalFormats list; each rule has a range, which can list several ranges separated by commas or spaces, such as 'B2:B50, D2:D50'.

Cell value rules#

TypeScript
sheet.addConditionalFormat({
  type: 'cellValue',
  range: 'E7:E366',
  operator: 'lessThan',
  values: [50000],
  style: { color: '#067647', bold: true },
});

Operators are between, notBetween, equal, notEqual, greaterThan, lessThan, greaterThanOrEqual and lessThanOrEqual. A value can be a formula such as '=$B$1*0.2'.

Text rules#

TypeScript
sheet.addConditionalFormat({ type: 'text', range: 'C2:C200', operator: 'contains', text: 'overdue', style: { fill: '#fef3f2' } });

contains, notContains, beginsWith and endsWith, ignoring case. A number is compared as its text, so beginsWith '20' matches 2026. A blank cell does not contain anything, so notContains matches it, as in Excel.

Blank cells and errors#

TypeScript
sheet.addConditionalFormat({ type: 'blanks', range: 'B2:F200', style: { fill: '#fff4e5' } });
sheet.addConditionalFormat({ type: 'errors', range: 'G2:G200', style: { color: '#b42318', bold: true } });

blanks matches empty cells and cells that hold only spaces; noBlanks matches the rest. errors matches cells whose value is an error such as #DIV/0! or #N/A; noErrors matches the rest.

Dates in a period#

TypeScript
sheet.addConditionalFormat({ type: 'dateOccurring', range: 'D2:D500', period: 'nextWeek', style: { fill: '#e0f2fe' } });

period is yesterday, today, tomorrow, last7Days, lastWeek, thisWeek, nextWeek, lastMonth, thisMonth or nextMonth. Weeks run from Sunday to Saturday, as in Excel, and last7Days includes today. The rule looks at cells that hold a date as a number and ignores the time of day. Today comes from the now option, so the same workbook formats the same way in a test and on a server.

Formula rules#

A formula rule applies its style where the formula is true. Write the formula for the top-left cell of the range; relative references shift for the other cells, as in Excel, and a $ keeps a row or a column fixed. This highlights whole rows of overdue invoices:

TypeScript
sheet.addConditionalFormat({
  type: 'formula',
  range: 'A2:F500',
  formula: '=AND($E2="Open", $D2<TODAY())',
  style: { fill: '#fff4e5' },
});

When the range lists several areas, the formula is written for the top-left cell of the first area and shifted from there for every cell of every area. The same holds for a formula used as the value of a cell value rule: values: ['=B2'] on C2:C50 compares each cell with its neighbour.

Inserting or deleting rows and columns moves the range and the references in the formula together, including the formulas of icon thresholds and data bar limits. An area that is deleted completely is removed from the range, and the rule goes when no area is left.

Colour scales#

TypeScript
sheet.addConditionalFormat({
  type: 'colorScale',
  range: 'C7:C366',
  min: { type: 'min', color: '#f8fafc' },
  mid: { type: 'percentile', value: 50, color: '#fde68a' },
  max: { type: 'max', color: '#f97316' },
});

Each stop is min, max, a number, a percent of the range or a percentile. mid is optional.

Data bars#

TypeScript
sheet.addConditionalFormat({ type: 'dataBar', range: 'D7:D366', color: '#2563eb' });

The bar length is relative to the range's values, or to explicit min and max. When the range has negative values, an axis is drawn at zero: positive bars run from the axis towards the end of the cell in the rule's colour, and negative bars run the other way in red.

TypeScript
sheet.addConditionalFormat({
  type: 'dataBar',
  range: 'E2:E60',
  color: '#2563eb',
  gradient: true,
  borderColor: '#1d4ed8',
  negativeColor: '#dc2626',
  negativeBorderColor: '#991b1b',
  axisPosition: 'midpoint',
  axisColor: '#475467',
  direction: 'leftToRight',
  minType: 'percentile',
  min: 5,
  maxType: 'formula',
  maxFormula: '=$H$1',
  showValue: false,
});
Option Meaning
gradient true fades the bar towards its end. The default is a solid bar.
borderColor Draws a border around the bar.
negativeColor, negativeBorderColor Fill and border of bars for negative values. The fill defaults to red, the border to borderColor. A negative border needs borderColor.
axisPosition 'automatic' (the default) puts the axis where zero falls between the limits. 'midpoint' puts it in the middle of the cell and scales each side on its own. 'none' draws no axis and negative bars in the same direction as positive ones.
axisColor Colour of the axis line.
direction 'context' (the default) follows the sheet direction, 'leftToRight' and 'rightToLeft' fix it.
minType, maxType How the limit is found: 'automatic', 'min' (lowest value), 'max' (highest value), 'number', 'percent', 'percentile' or 'formula'. min and max hold the number for number, percent and percentile; minFormula and maxFormula hold the formula. Without a type, a min or max is a number and a missing one is automatic. An automatic minimum is the lowest value or zero, whichever is lower.
showValue false shows the bar without the cell's text.

Top and bottom values#

TypeScript
sheet.addConditionalFormat({ type: 'topBottom', range: 'E2:E120', direction: 'top', rank: 10, style: { fill: '#c6efce' } });
sheet.addConditionalFormat({ type: 'topBottom', range: 'E2:E120', direction: 'bottom', rank: 5, percent: true, style: { color: '#9c0006' } });

rank is a count, or a percentage of the numeric cells when percent is true. Ties with the cut-off value are included, as in Excel.

Above or below average#

TypeScript
sheet.addConditionalFormat({ type: 'average', range: 'C2:C40', operator: 'below', style: { fill: '#ffc7ce' } });

operator is 'above', 'below', 'aboveOrEqual' or 'belowOrEqual'. The average covers the numeric cells of the rule's range.

Duplicate and unique values#

TypeScript
sheet.addConditionalFormat({ type: 'duplicates', range: 'A2:A500', style: { fill: '#ffeb9c' } });
sheet.addConditionalFormat({ type: 'duplicates', range: 'B2:B500', unique: true, style: { bold: true } });

Text is compared without regard to case. Blank cells are never duplicates.

Icon sets#

TypeScript
sheet.addConditionalFormat({ type: 'iconSet', range: 'F2:F60', iconSet: '3TrafficLights1' });
sheet.addConditionalFormat({
  type: 'iconSet',
  range: 'G2:G60',
  iconSet: '3Arrows',
  thresholds: [
    { type: 'number', value: 0 },
    { type: 'number', value: 0.05 },
  ],
  showValue: false,
});

All twenty icon sets of Excel are available:

Icons Sets
Three 3Arrows, 3ArrowsGray, 3Flags, 3TrafficLights1, 3TrafficLights2, 3Signs, 3Symbols, 3Symbols2, 3Stars, 3Triangles
Four 4Arrows, 4ArrowsGray, 4RedToBlack, 4Rating, 4TrafficLights
Five 5Arrows, 5ArrowsGray, 5Rating, 5Quarters, 5Boxes

Without thresholds the range is split into equal percentage bands, from the lowest icon to the highest. Give one threshold fewer than the number of icons, lowest first. Each has a type: number, percent of the range, percentile, or formula with the formula in formula. A cell gets the icon of the highest threshold it reaches; inclusive: false on a threshold means the value must be above it, not at it. reverse flips the order and showValue: false shows the icon alone.

TypeScript
sheet.addConditionalFormat({
  type: 'iconSet',
  range: 'H2:H60',
  iconSet: '3TrafficLights1',
  thresholds: [
    { type: 'percentile', value: 25 },
    { type: 'formula', value: 0, formula: '=$K$1', inclusive: false },
  ],
  icons: [
    { iconSet: '3Flags', iconId: 0 },
    { iconSet: 'NoIcons', iconId: 0 },
    { iconSet: '3Stars', iconId: 2 },
  ],
});

icons picks an icon for each band on its own, lowest band first: a set and the position of the icon in it, counted from 0 at the icon for the lowest values. { iconSet: 'NoIcons', iconId: 0 } leaves a band without an icon. Give exactly one entry per icon of the rule's set, or the list is ignored; reverse has no effect with custom icons.

The icons are drawn as text characters in fixed colours, not as Excel's pictures, so they look similar but not the same. The icon sits at the start of the cell and is hidden from screen readers, which still hear the value.

The rule dialog#

Conditional formatting on the Home tab, and openDialog('conditionalFormat'), open a dialog that creates these rules: greater than, less than, between and equal to; text that contains, does not contain, begins with or ends with; a date in a period; blank and non-blank cells; cells with and without errors; duplicate values; top and bottom items; above and below average; and a formula. Each takes one of five highlight styles or a Custom format…, and has a Stop if true box. Custom format, and the Format… button beside the list, open a format picker with the Number, Font, Fill and Border tabs of Format Cells, so a rule can set any font attribute, fill, border and number format; a sample next to the list shows the result. The dialog also creates data bars with all their options, colour scales with two or three points (each with a type of lowest or highest value, number, percent or percentile, a value and a colour, and a preview of the gradient), and icon sets with their thresholds, order and custom icons. When the range already has a data bar, a colour scale or an icon set with exactly that range, the dialog opens with its settings and replaces it. Every field has a label, and the dialog works from the keyboard: Tab moves through the fields, Enter applies and Escape cancels. Colours are typed as #rrggbb. The other comparison operators and unique values are set in code; the order of rules is set in the rules manager.

The rules manager#

Home › Conditional formatting › Manage rules…, and openDialog('conditionalRules'), list the rules of the current selection or of the whole worksheet, highest priority first. For each rule you can:

  • change Applies to, with one or more ranges;
  • tick Stop if true (not offered for colour scales, data bars and icon sets);
  • move it up or down, which changes its priority and therefore what is painted where rules overlap;
  • open it in the rule dialog with Edit, or delete it.

New rule… adds a rule at the top. Nothing changes on the sheet until OK; the whole set of changes is then one undo step, and the order is the order saved to xlsx. A colour scale opens in the rule dialog like any other rule.

TypeScript
const rules = sheet.getConditionalFormats();
sheet.setConditionalFormats([rules[1], rules[0], ...rules.slice(2)]);

How rules combine#

Rules are checked in the order of the list, which is their priority: the first rule has the highest. For each style property, the earliest matching rule wins; a cell gets at most one colour scale fill, one data bar and one icon. A rule with stopIfTrue: true that matches a cell ends the checking for that cell, so no later rule applies to it; colour scales, data bars and icon sets cannot stop the checking, as in Excel. Adding and clearing rules is undoable. clearConditionalFormats(sheet?) removes all rules from a sheet.

Conditional formats are kept in the workbook JSON. See Excel files for how each rule type is saved to xlsx.

The Format Cells dialog#

Ctrl + 1, Format cells… in the context menu, or openDialog('formatCells') opens the Format Cells dialog. It applies to every selected cell, and changes only the properties you touch.

  • Number: General, Number, Currency, Accounting, Date, Time, Percentage, Fraction, Scientific, Text and Custom. Set the decimal places, the thousands separator, the negative number style and the currency symbol, with a live preview of the active cell.
  • Alignment: horizontal alignment (General, Left, Center, Right, Fill, Justify, Center across selection, Distributed), vertical alignment (Bottom, Middle, Top, Justify, Distributed), indent, orientation in degrees from -90 to 90, vertical (stacked) text, wrap text, shrink to fit and text direction.
  • Font: family, size, bold, italic, underline, strikethrough, the underline style (single, double, single accounting, double accounting), superscript or subscript, and colour.
  • Fill: the fill type. Solid color takes a background colour or no colour. Gradient takes two colours and a direction: Horizontal, Vertical, Diagonal up, Diagonal down or From center. Pattern takes one of the 17 pattern styles, a pattern colour and the background colour. A sample shows the result.
  • Border: outline, all, inside, a single side, diagonal up, diagonal down or none, with a line-style picker that shows all 13 styles, and the line colour. Arrow keys move through the line styles.
  • Protection: Locked and Hidden, which take effect when the sheet is protected (see Protection).

Tabs use the ARIA tabs pattern: arrow keys move between them.

On the Home tab of the ribbon, the Alignment group has an Orientation menu (Angle counterclockwise, Angle clockwise, Vertical text, Rotate text up, Rotate text down, and Format cell alignment… for the dialog) and Decrease indent and Increase indent buttons.

The gallery has Excel's built-in styles: Good, Bad and Neutral; Calculation, Check Cell, Explanatory Text, Input, Linked Cell, Note, Output and Warning Text; Title, Heading 1 to 4 and Total; and Comma, Currency and Percent. Open it with Cell styles… in the context menu or with openDialog('cellStyles'), or apply a style from code:

TypeScript
sheet.applyCellStyle('A1:F1', 'Heading 1');
sheet.applyCellStyle('B2:E13', 'Input');
sheet.applyCellStyle('F14', 'Total');
sheet.listCellStyles(); // [{ name: 'Normal', category: 'goodBadNeutral', style: {} }, …]
NamedCellStyleinterface@birchui/spreadsheetFull reference
PropertyTypeDescription
namestring—
category'goodBadNeutral' | 'dataModel' | 'titles' | 'numberFormat' | 'workbook'—
styleCellStyle—

When the workbook has its own named styles in cellStyles, which is the case for an imported Excel file, the gallery lists them first under From this workbook, and listCellStyles() returns them with the category 'workbook'. A workbook style with the same name as a built-in one takes its place. Applying a workbook style replaces the cell's formatting, including the number format when the style has one, and sets styleName so the exported cell stays linked to the style. Applying a built-in style removes styleName.

A built-in formatting style replaces the font, fill, border and alignment properties and keeps the number format. A number format style changes only the number format. Applying a style is one undo step.

Locales#

By default numbers are shown with a decimal point, month and day names are English and a typed 3/9/2026 is 9 March. The locale option changes that for the whole component:

TypeScript
const sheet = createSpreadsheet(host, { locale: 'de-DE', localizedFormulas: true });
en-US de-DE fr-FR es-ES
1234567.891 as #,##0.00 1,234,567.89 1.234.567,89 1 234 567,89 1.234.567,89
Serial 46090 as dddd, d. mmmm yyyy Monday, 9. March 2026 Montag, 9. März 2026 lundi, 9. mars 2026 lunes, 9. marzo 2026
Typed 1.234,5 text 1234.5 text 1234.5
Typed 9.3.2026 or 9/3/2026 3 September 2026 for the second 9 March 2026, shown as 09.03.2026 9 March 2026 9 March 2026
=IF(SUM(A1:A3)>1.5,1,0) with localizedFormulas unchanged =WENN(SUMME(A1:A3)>1,5;1;0) =SI(SOMME(A1:A3)>1,5;1;0) =SI(SUMA(A1:A3)>1,5;1;0)

What the locale changes:

  • Display. The decimal and thousands separators that a number format produces, and the month and day names of date formats. The format codes themselves stay as Excel stores them (#,##0.00, mmmm), so files and JSON are the same in every locale.
  • Typed input. Numbers with the locale's separators and day-first dates are recognised when typed into a cell or the formula bar. The stored value is a plain number.
  • Formulas, when localizedFormulas is true. The editor and the formula bar show the argument separator, decimal comma, array separators and function names of the locale, and accept them when you type. The formula is stored in the en-US form, so getFormula(), toJSON() and exported files do not change. formulaToLocale() and formulaFromLocale() do the same conversion for your own UI.

What it does not change: text passed to setValue() or pasted, the TEXT() function and text-to-number conversion inside formulas (all en-US), the words TRUE and FALSE in cells, the argument hint under the editor, and function autocomplete, which lists English names (an English name is always accepted).

About 70 of the most used function names are translated per language, taken from Excel's own translations; any other function keeps its English name in that language. To add names or a whole language, pass a locale object instead of a tag:

TypeScript
import { DE_DE } from '@birchui/spreadsheet';

createSpreadsheet(host, {
  locale: { ...DE_DE, functionNames: { ...DE_DE.functionNames, XIRR: 'XINTZINSFUSS' } },
  localizedFormulas: true,
});

formatValue(value, code, { locale }) and jsonToPdf(json, { locale }) take the same option. The translated names were written from Excel's documentation and have not been checked against a localized Excel installation.

↑ ↓ to move, Enter to open, Esc to close