typed-xlsx
Columns

Rich Text

Write cells and table titles with several fonts in one text, such as a bold word followed by plain text.

richText() builds text made of runs, each with its own font. Use it where a cell value or a table title would be a string.

import { 
createExcelSchema
,
createWorkbook
,
richText
} from "typed-xlsx";
type
Invoice
= {
id
: string;
dueInDays
: number };
const
schema
=
createExcelSchema
<
Invoice
>()
.
column
("id", {
header
: "Invoice",
accessor
: "id" })
.
column
("status", {
header
: "Status",
accessor
: "dueInDays",
transform
: ({
value
}) =>
value
< 0
?
richText
([
{
text
: "Overdue",
font
: {
bold
: true,
color
: {
rgb
: "B91C1C" } } },
` since ${-
value
} days`,
]) : "On time", }) .
build
();
createWorkbook
()
.
sheet
("Invoices")
.
table
("invoices", {
title
:
richText
([{
text
: "Q1",
font
: {
bold
: true } }, " invoices"]),
schema
,
rows
: [{
id
: "INV-1",
dueInDays
: -3 }],
});

A run is a string, or { text, font } where font takes the same options as a cell style's font: bold, italic, underline, strike, color, size and name. Options a run leaves out come from the cell's style (the column style, a per-row style callback, or the theme for titles), so a plain string run looks like the rest of the cell. The cell's font is written into each run, since Excel reads a run's font on its own rather than on top of the cell's.

Where it is accepted

Rich text is a cell value: an accessor, a transform or a defaultValue can return it, one per sub-row on expanded rows too. A report table's title takes it as well.

Column and group headers, sheet names, table names, dropdown lists and hyperlink targets stay plain strings, since Excel uses them as names. TypeScript rejects rich text there.

Column widths, pivot tables and totals read the plain text of the runs.

In the file

Rich text is always written inline in the cell (<is> with one <r> per run), in buffered and streamed workbooks and with either string mode, so the shared strings table only ever holds plain text. A value only counts as rich text when richText() built it: an object that merely looks like one is rejected like any other object.

Copyright © 2026 Cyprien Thao. Released under the MIT License.