Result: A1 is bold, 16 px Georgia, wrapped and top-aligned. A2:B4 use Calibri at 11 pt and align to the bottom. Fonts fall back to the theme font when unavailable.
// 14.666666666666666 (11 pt: the theme's 13px rounds to 10 pt, and the next standard size is 11 pt)
A1 shows a bold, 16 px Georgia title that wraps and starts at the top of the cell. A2:B4 paint in Calibri at 11 pt, at the bottom of their rows.
Font and alignment fields
These CellStyle fields control text. All of them are optional.
Field
Type
Effect
fontFamily
string
One font family, for example "Calibri". The theme font is the fallback.
fontSize
number
Font size in CSS pixels.
bold
boolean
Bold text.
italic
boolean
Italic text.
underline
boolean
Underlined text.
strikethrough
boolean
Struck-through text.
color
string
Hex text color, for example "#111111".
align
"left" | "center" | "right"
Horizontal alignment.
verticalAlign
"top" | "middle" | "bottom"
Vertical alignment. Omitted means centered.
wrap
boolean
Wrap text onto more lines inside the cell.
Paint, column auto-fit, snapshots, the clipboard and hyperlink styles all honor fontFamily, verticalAlign and numberFormat.
Font family names
fontFamily names one family. Sheetwrite draws it before the theme font's families, so a font that the browser does not have falls back to the theme font.
A valid name has 1 to 128 characters: letters, digits, spaces, ., _ and -. It starts with a letter or a digit and does not end in a space. isCellFontFamily(value) from @sheetwrite/core applies this rule. The same rule guards snapshots, hyperlinks, the clipboard and XLSX import.
isCellFontFamily("Arial, sans-serif"); // false: a comma is not allowed
Grid actions
grid.actions holds the commands behind the toolbar and the ribbon. Each command applies to every cell of the current selection. It does nothing when the grid is read-only or the selection is empty.
Command
Effect
setFontFamily(family: string | null)
Sets the font family. null returns the cells to the column or theme font.
setFontSize(size: number | null)
Sets the font size in CSS pixels. null returns the cells to the default.
stepFontSize(direction: 1 | -1)
Steps the focus cell's font size to the next larger (1) or smaller (-1) standard size, and applies it to the selection.
setVerticalAlign(align: CellVerticalAlign)
Sets verticalAlign to "top", "middle" or "bottom".
toggleWrap()
Sets wrap to the opposite of the focus cell's wrap.
The start size is the focus cell's fontSize. If the cell has none, it is the pixel size in the theme font (13 px when the theme font has no pixel size).
Sheetwrite converts pixels to points at 96/72 pixels per point and rounds to the nearest half point.
Above 72 pt, a step up goes to the next multiple of 10 points. Below 8 pt, a step down removes 1 point and stops at 1 pt.
The ribbon's font list calls setFontFamily (an empty name sends null). Its size box calls setFontSize with the points converted to pixels. Increase Font Size and Decrease Font Size call stepFontSize(1) and stepFontSize(-1). Top Align, Middle Align and Bottom Align call setVerticalAlign, and Wrap Text calls toggleWrap.
Updated in 0.6.0. An XLSX cell with no vertical alignment is bottom-aligned in Excel, but an unset Sheetwrite cell paints centered. Import and export now convert between the two defaults, so imported files look as they do in Excel. LibreOffice reads and writes the same XLSX attributes, and the LibreOffice round trip has no vertical-alignment differences.
Visible change: imported cells with no vertical alignment now sit at the bottom, as in Excel.
Import (cell styles):
XLSX <alignment vertical>
Sheetwrite verticalAlign
No <alignment>, or no vertical attribute
"bottom"
bottom
"bottom"
top
"top"
center
Unset (the grid default, centered)
center, in a column whose default is "bottom"
"middle" (an explicit value overrides the column default)
A workbook with no styles part imports every cell as "bottom".
Export (cell styles):
Sheetwrite verticalAlign
XLSX <alignment vertical>
Unset
center
"middle"
center
"top"
top
"bottom"
No vertical attribute (the XLSX default)
Export also writes the workbook's normal cell style with vertical="center", so unstyled cells stay centered.
Conditional-format styles are differential: they change only the fields they set. For them, import maps center to "middle", top and bottom to the same names, and a missing attribute to unset. Export writes only a value that the style sets ("middle" as center).
Fonts on import: only fonts other than the workbook default become a cell fontFamily.
Edge cases and limits
wrap applies to text, not to numbers. A number that does not fit its cell paints as # characters.
A wrapped block that is taller than its cell starts at the top of the cell.
Text that does not wrap can spill past its cell: left-aligned text to the right, right-aligned text to the left, and centered text to both sides. Numbers never spill.
Native boolean values are centered unless CellStyle.align overrides it.
A font that the browser does not have falls back to the theme font.
const grid: Gridconstgrid:Gridconstgrid:GridThe imperative core grid this controller owns.API reference →Grid.styleRange(range: Range, style: Partial<CellStyle> | null): voidGrid.styleRange(range: Range, style: Partial<CellStyle>|null): voidGrid.styleRange(range: Range, style: Partial<CellStyle>|null): voidMerge style into every cell of range (null clears cell styles) as one undoable transaction. Styles land in the store and paint in the canvas — unlike highlightCells, which draws a translucent overlay above it.API reference →Range.sheet: stringinterfaceRange {sheet:string;}interfaceRange {sheet:string;}Sheet identity used by the simple data-first adapter. Defaults to sheet1.API reference →Range.start: {
row: number;
col: number;
}interfaceRange {start: {row:number;col:number;};}interfaceRange {start: {row:number;col:number;};}Zero-based workbook column index of the first key.API reference →row: numberlet row:numberlet row:number0-based row of the cell that holds the top-left corner.API reference →col: numberlet col:numberlet col:number0-based column of the cell that holds the top-left corner.API reference →Range.end: {
row: number;
col: number;
}interfaceRange {end: {row:number;col:number;};}interfaceRange {end: {row:number;col:number;};}Exclusive workbook column index after the last key.API reference →fontFamily?: string | undefinedfontFamily?: string |undefinedfontFamily?: string |undefinedFont family name, e.g. "Calibri". The theme font family stays the fallback, so a font the browser lacks renders in the theme font. Letters, digits, spaces, ., _ and - only; at most 128 characters.API reference →fontSize?: number | undefinedfontSize?: number |undefinedfontSize?: number |undefinedFont size in unzoomed CSS pixels; zoom is applied during painting.API reference →bold?: boolean | undefinedbold?: boolean |undefinedbold?: boolean |undefinedUses the bold variant of the theme font.API reference →wrap?: boolean | undefinedwrap?: boolean |undefinedwrap?: boolean |undefinedWraps text within the cell width; row auto-fit accounts for the resulting line count.API reference →verticalAlign?: CellVerticalAlign | undefinedverticalAlign?: CellVerticalAlign |undefinedverticalAlign?: CellVerticalAlign |undefinedVertical placement of cell text; omitted keeps text centered.API reference →Grid.setSelection(sel: Selection | null): voidGrid.setSelection(sel: Selection |null): voidGrid.setSelection(sel: Selection |null): voidkind: "range"let kind:"range"let kind:"range"Selects one inclusive rectangular range.range: Rangelet range:Rangelet range:RangeData-space bounds of the selected rectangle.API reference →Grid.actions: GridActionsinterfaceGrid {actions:GridActions;}interfaceGrid {actions:GridActions;}Imperative action surface for binding custom toolbars/menus.API reference →GridActions.setFontFamily(family: string | null): voidGridActions.setFontFamily(family: string |null): voidGridActions.setFontFamily(family: string |null): voidSet the selection's font family; null returns it to the column/theme font.API reference →GridActions.stepFontSize(direction: 1 | -1): voidGridActions.stepFontSize(direction: 1|-1): voidGridActions.stepFontSize(direction: 1|-1): voidStep the focus cell's font size to the next larger (1) or smaller (-1) standard size.API reference →GridActions.setVerticalAlign(align: CellVerticalAlign): voidGridActions.setVerticalAlign(align: CellVerticalAlign): voidGridActions.setVerticalAlign(align: CellVerticalAlign): voidfunction createGrid(host: HTMLElement, opts: GridOptions): GridfunctioncreateGrid(host:HTMLElement,opts:GridOptions,):GridfunctioncreateGrid(host:HTMLElement,opts:GridOptions,):GridCreates and mounts an imperative Grid in the supplied host element.Exampleimport { createGrid, initSheetwrite } from"@sheetwrite/core";awaitinitSheetwrite();consthost= document.createElement("div");host.style.height ="400px";document.body.append(host);constgrid=createGrid(host, {workbook: {activeSheet: "sales",sheets: [{ id: "sales", name: "Sales", rowCount: 2,columns: [{ key: "amount", header: "Amount", type: "number", width: 120 }] }],},data: { rowCount: 2, columns: { amount: [12, 18] } },});grid.scrollToCell({ sheet: "sales", row: 1, col: 0 });// Call when the host view is removed.grid.destroy();See alsoGrid *See alsoGridOptionsAPI reference →function initSheetwrite(source?: BufferSource | URL | string | Request | WebAssembly.Module, engine?: SheetwriteEngine): Promise<void>functioninitSheetwrite(source?:BufferSource|URL|string|Request|WebAssembly.Module,engine?:SheetwriteEngine,):Promise<void>functioninitSheetwrite(source?:|BufferSource|URL|string|Request|WebAssembly.Module,engine?:SheetwriteEngine,):Promise<void>Load one WASM engine before createGrid. The default is @sheetwrite/wasm. Pass the @sheetwrite/formulas module as the second argument to select the full engine.Exampleimport { initSheetwrite } from"@sheetwrite/core";import*as formulas from"@sheetwrite/formulas";awaitinitSheetwrite(undefined, formulas);See also/docs/start/choose-an-engine/See alsocreateGridAPI reference →interface ColumnarDatainterfaceColumnarDatainterfaceColumnarDataEager column-oriented values used to initialize a sheet.API reference →interface WorkbookinterfaceWorkbookinterfaceWorkbookLive workbook schema containing ordered sheets and the active sheet ID.API reference →const host: HTMLElement | nullconsthost:HTMLElement|nullconsthost:HTMLElement|nullvar document: Documentvar document:Documentvar document:Documentwindow.document returns a reference to the document contained in the window. MDN ReferenceAPI reference →ParentNode.querySelector<HTMLElement>(selectors: string): HTMLElement | null (+4 overloads)ParentNode.querySelector<HTMLElement>(selectors: string): HTMLElement |null (+4 overloads)ParentNode.querySelector<HTMLElement>(selectors: string): HTMLElement |null (+4 overloads)Returns the first element that is a descendant of node that matches selectors. MDN Referenceinterface HTMLElementinterfaceHTMLElementinterfaceHTMLElementThe HTMLElement interface represents any HTML element. MDN Referencevar Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+2 overloads)var Error:ErrorConstructornew (message?:string, options?:ErrorOptions) =>Error (+2 overloads)var Error:ErrorConstructornew (message?:string, options?:ErrorOptions) =>Error (+2 overloads)const host: HTMLElementconsthost:HTMLElementconsthost:HTMLElementElementCSSInlineStyle.style: CSSStyleDeclarationinterfaceElementCSSInlineStyle {style:CSSStyleDeclaration;}interfaceElementCSSInlineStyle {style:CSSStyleDeclaration;}MDN ReferenceAPI reference →CSSStyleDeclaration.height: stringinterfaceCSSStyleDeclaration {height:string;}interfaceCSSStyleDeclaration {height:string;}MDN ReferenceAPI reference →const workbook: Workbookconstworkbook:Workbookconstworkbook:WorkbookLive workbook schema adopted by the store and updated by document operations.API reference →Workbook.activeSheet: stringinterfaceWorkbook {activeSheet:string;}interfaceWorkbook {activeSheet:string;}Active sheet ID and initial tab presented when the grid is created.API reference →Workbook.sheets: Sheet[]interfaceWorkbook {sheets:Sheet[];}interfaceWorkbook {sheets:Sheet[];}Sheets in display/tab order.API reference →Sheet.id: stringinterfaceSheet {id:string;}interfaceSheet {id:string;}Stable identifier, unique within the workbook and used by every cell address.API reference →Sheet.name: stringinterfaceSheet {name:string;}interfaceSheet {name:string;}User-facing sheet name shown in tabs and workbook exports.API reference →Sheet.rowCount: numberinterfaceSheet {rowCount:number;}interfaceSheet {rowCount:number;}Row count for both in-memory and datasource-backed sheets.API reference →Sheet.columns: Column[]interfaceSheet {columns:Column[];}interfaceSheet {columns:Column[];}Ordered schema; array positions are the zero-based column coordinates.API reference →Column.key: stringinterfaceColumn {key:string;}interfaceColumn {key:string;}Non-empty key, unique within the sheet, used to map input and datasource values.API reference →Column.header: stringinterfaceColumn {header:string;}interfaceColumn {header:string;}Schema label used by table exports and data-grid presentation headers.API reference →Column.width: numberinterfaceColumn {width:number;}interfaceColumn {width:number;}Unzoomed column width in CSS pixels.API reference →Column.type: CellFormatinterfaceColumn {type:CellFormat;}interfaceColumn {type:CellFormat;}Controls cell input parsing and default value formatting for this column.API reference →const data: ColumnarDataconstdata:ColumnarDataconstdata:ColumnarDataEager column-major values loaded into workbook.activeSheet; use instead of datasource.API reference →ColumnarData.rowCount: numberinterfaceColumnarData {rowCount:number;}interfaceColumnarData {rowCount:number;}Row count for both in-memory and datasource-backed sheets.API reference →ColumnarData.columns: Record<string, ArrayLike<CellScalar | CellValue>>interfaceColumnarData {columns:Record<string, ArrayLike<CellScalar|CellValue>>;}interfaceColumnarData {columns:Record<string,ArrayLike<CellScalar|CellValue>>;}Exact column runs represented by every returned row.API reference →region: string[]let region:string[]let region:string[]sales: Float64Array<ArrayBuffer>let sales:Float64Array<ArrayBuffer>let sales:Float64Array<ArrayBuffer>var Float64Array: Float64ArrayConstructor
new (elements: Iterable<number>) => Float64Array<ArrayBuffer> (+6 overloads)var Float64Array:Float64ArrayConstructornew (elements:Iterable<number>) =>Float64Array<ArrayBuffer> (+6 overloads)var Float64Array:Float64ArrayConstructornew (elements:Iterable<number>) =>Float64Array<ArrayBuffer> (+6 overloads)GridOptions.workbook: WorkbookinterfaceGridOptions {workbook:Workbook;}interfaceGridOptions {workbook:Workbook;}Live workbook schema adopted by the store and updated by document operations.API reference →GridOptions.data?: ColumnarData | undefinedinterfaceGridOptions {data?:ColumnarData|undefined;}interfaceGridOptions {data?:ColumnarData|undefined;}Eager column-major values loaded into workbook.activeSheet; use instead of datasource.API reference →var console: Consolevar console:Consolevar console:ConsoleConsole.log(...data: any[]): void (+1 overload)Console.log(...data: any[]): void (+1 overload)Console.log(...data: any[]): void (+1 overload)The console.log() static method outputs a message to the console. MDN ReferenceGrid.store: StoreinterfaceGrid {store:Store;}interfaceGrid {store:Store;}Store.getCell(addr: CellAddress): ResolvedCellStore.getCell(addr: CellAddress): ResolvedCellStore.getCell(addr: CellAddress): ResolvedCellSingle-cell read for interactions, API reads, and tests. NOT for the render hot path — renderers use getVisibleWindow.API reference →CellAddress.sheet: stringinterfaceCellAddress {sheet:string;}interfaceCellAddress {sheet:string;}Sheet identity used by the simple data-first adapter. Defaults to sheet1.API reference →CellAddress.row: numberinterfaceCellAddress {row:number;}interfaceCellAddress {row:number;}0-based row of the cell that holds the top-left corner.API reference →CellAddress.col: numberinterfaceCellAddress {col:number;}interfaceCellAddress {col:number;}0-based column of the cell that holds the top-left corner.API reference →ResolvedCell.style: CellStyleinterfaceResolvedCell {style:CellStyle;}interfaceResolvedCell {style:CellStyle;}Optional override merged over the deterministic blue/underline link style.API reference →CellStyle.fontSize?: number | undefinedinterfaceCellStyle {fontSize?:number|undefined;}interfaceCellStyle {fontSize?:number|undefined;}Font size in unzoomed CSS pixels; zoom is applied during painting.API reference →function isCellFontFamily(value: string): booleanfunctionisCellFontFamily(value:string):booleanfunctionisCellFontFamily(value:string,):booleanWhether value is a valid cell fontFamily: 1-128 letters, digits, spaces, ., _ or -, starting with a letter or digit and not ending in a space. The same rule guards snapshots, hyperlinks, clipboard and XLSX import.API reference →GridActions.toggleWrap(): voidGridActions.toggleWrap(): voidGridActions.toggleWrap(): voidAPI reference →GridActions.setFontSize(size: number | null): voidGridActions.setFontSize(size: number |null): voidGridActions.setFontSize(size: number |null): voidSet the selection's font size in CSS pixels; null returns it to the default.API reference →