Result: Home is open above the Budget sheet. Three command groups are excerpted here; Undo and Redo are disabled because there is no edit history. This is a static preview.
The ribbon appears above the grid with the Home, Insert, Data and View tabs.
The ribbon has four tabs with Excel's group names, labels and order:
Tab
Groups and controls
Home
Undo. Clipboard: Paste split button. Font: font name and size boxes, grow and shrink, bold, italic, underline, strikethrough, Borders, Fill Color and Font Color palettes. Alignment: top, middle, bottom, wrap, left, center, right, Merge & Center. Number: format box, currency, percent, comma, more and fewer decimals. Cells: Insert, Delete, Format. Editing: AutoSum, Clear, Sort & Filter, Find.
Insert
Rows & Columns: Insert (rows above or below, columns left or right), Delete (rows or columns). Links: link form. Notes: note form.
Data
Sort & Filter: Sort A to Z, Sort Z to A, Clear Filter. Outline: Group and Ungroup rows. Show/Hide: Hide Rows, Unhide Rows, Hide Columns, Unhide Columns.
View
Window: Freeze Panes, Freeze Top Row, Freeze First Column, Unfreeze Panes. Zoom: zoom out, current percent, zoom in.
Every control reads the same getCommandState contract as host chrome. It disables while the grid is read-only.
Narrow widths
As the grid narrows, the ribbon shrinks the way Excel does:
Large buttons become small ones.
Labels go.
Whole groups fold into one dropdown button that opens the group in a popup.
Groups fold in Excel order. On Home, Editing folds first, then Cells, Number, Alignment, Clipboard, Font and Undo.
Double-click a tab, or use the arrow at the right, to hide the panel and keep only the tab row. The grid takes the space back.
Keyboard
Key
Effect
Tab
Reaches the tab row. The ribbon is first in the host, so keyboard users reach it before the grid.
Arrow keys
Move between tabs, and through menus and lists.
Enter
Picks a menu or list item.
Escape
Returns focus to the grid.
Ctrl/Cmd shortcuts
Still reach the grid, for example undo. Plain keys stay in the ribbon.
Loading
The ribbon loads with import() as its own chunk, only when a grid asks for it. A grid without the ribbon does not download it; that is about 25 KB less minified JavaScript.
The grid reserves the ribbon's height while the chunk loads, so nothing moves when it arrives.
A chunk that arrives after the chrome was rebuilt, or after the grid was destroyed, is dropped.
If the chunk fails to load, the grid shows the flat toolbar. The load error is still reported as an unhandled promise rejection; the host cannot catch it.
Ribbon outside the grid
The composable shell mounts the same ribbon. Pass ribbon: true to createSpreadsheetShell, or call createRibbon to place it yourself:
Returns keyboard focus to the grid after a pick or Escape. By default the host gets focus.
onHeightChange
Called with the new height after the ribbon is minimized or expanded.
The ribbon styles itself from the same --sheetwrite-widget-*, --sheetwrite-toolbar-* and --sheetwrite-menu-* properties as the toolbar, so light, dark and host themes apply.
GridConfig (toolbar)
Each flag toggles one control. When config is present, every flag except export and ribbon defaults to true. toolbar: false suppresses the toolbar entirely.
Master switch. false removes the toolbar. An item list replaces the default controls.
undo
boolean
true
Undo / redo buttons (also bound to Ctrl+Z / Ctrl+Shift+Z).
bold
boolean
true
Bold toggle.
italic
boolean
true
Italic toggle.
align
boolean
true
Left / center / right alignment.
textColor
boolean
true
Text color picker.
fillColor
boolean
true
Fill (background) color picker.
border
boolean
true
Border control.
clearFormat
boolean
true
Clear formatting.
merge
boolean
true
Merge / unmerge selection.
sort
boolean
true
Sort the selected column ascending / descending.
export
boolean
false
CSV / XLSX export buttons.
ribbon
boolean
false
Show the Excel-style ribbon instead of the flat toolbar.
¹ "Default true" means: when you supply a config object at all. With no config there is no toolbar.
The underline and strikethrough toggles show when bold or italic is on.
Toolbar actions
Every control acts on the current selection; see Interaction → Selection model. A custom toolbar: ToolbarItem[] list names built-in actions, separators, or onClick(grid) callbacks:
The export flag always enables CSV. The XLSX button requires an explicit optional installation and import "@sheetwrite/xlsx/register" before use. The framework packages do not install an XLSX backend.
Direct grid.exportXlsx(...) calls reject on failure.
Built-in toolbar and context-menu actions show an alert and emit one export-error event for CSV or XLSX failures.
grid.actions.exportXlsx() returns a promise that does not reject.
Built-in buttons show a busy state and ignore repeated starts while their command is pending.
Host-owned command state
Host chrome can use grid.actions without duplicating selection or history logic. Query one command with grid.getCommandState(name), or subscribe to the complete snapshot through command-state-change (onCommandStateChange in React and Svelte, @command-state-change in Vue):
Undo, redo and find are keyboard-driven and work without the toolbar: Ctrl+Z undoes the last edit, Ctrl+Shift+Z redoes it, and Ctrl+F opens the find widget (unless find: false).
Edge cases and limits
The per-control flags apply to the flat toolbar only, not to the ribbon.
A custom toolbar: [...] item list still renders the flat toolbar, even with ribbon: true.
toolbar: false removes both the toolbar and the ribbon.
Command-state aggregation is bounded. Very large selections conservatively report mixed instead of forcing an unbounded cell walk.
grid.setConfig(config) reconfigures the built-in chrome without replacing the grid or clearing selection and history.
const grid: Gridconstgrid:Gridconstgrid:GridThe imperative core grid this controller owns.API reference →function 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 →const host: HTMLElementconsthost:HTMLElementconsthost:HTMLElementGridOptions.workbook: WorkbookinterfaceGridOptions {workbook:Workbook;}interfaceGridOptions {workbook:Workbook;}Live workbook schema adopted by the store and updated by document operations.API reference →GridOptions.config?: GridConfig | undefinedinterfaceGridOptions {config?:GridConfig|undefined;}interfaceGridOptions {config?:GridConfig|undefined;}Built-in UI controls; providing an object enables the toolbar unless toolbar is false.API reference →GridConfig.ribbon?: boolean | undefinedinterfaceGridConfig {ribbon?:boolean|undefined;}interfaceGridConfig {ribbon?:boolean|undefined;}Replace the built-in toolbar with an Excel-style ribbon (Home, Insert, Data and View tabs) that narrows its groups as the grid gets narrower. A custom toolbar item list still renders the flat toolbar instead.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.getCommandState(command: GridCommandName): GridCommandStateGrid.getCommandState(command: GridCommandName): GridCommandStateGrid.getCommandState(command: GridCommandName): GridCommandStateQuery undo/redo availability and formatting active/mixed/disabled state.API reference →GridCommandState.disabled: booleaninterfaceGridCommandState {disabled:boolean;}interfaceGridCommandState {disabled:boolean;}Static or context-aware disabled state.API 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 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)ElementCSSInlineStyle.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 →function createRibbon(host: HTMLElement, grid: Grid, options?: RibbonOptions): ShellPiecefunctioncreateRibbon(host:HTMLElement,grid:Grid,options?:RibbonOptions,):ShellPiecefunctioncreateRibbon(host:HTMLElement,grid:Grid,options?:RibbonOptions,):ShellPieceMount an Excel-style ribbon (Home, Insert, Data, View) bound to grid.actions, in normal document flow. Groups shrink, then collapse into dropdowns, as the host narrows. Returns the piece with an idempotent destroy.API reference →const ribbonHost: HTMLDivElementconstribbonHost:HTMLDivElementconstribbonHost:HTMLDivElementDocument.createElement<"div">(tagName: "div", options?: ElementCreationOptions): HTMLDivElement (+2 overloads)Document.createElement<"div">(tagName: "div", options?: ElementCreationOptions): HTMLDivElement (+2 overloads)Document.createElement<"div">(tagName: "div", options?: ElementCreationOptions): HTMLDivElement (+2 overloads)In an HTML document, the document.createElement() method creates the HTML element specified by localName, or an HTMLUnknownElement if localName isn't recognized. MDN ReferenceChildNode.before(...nodes: (Node | string)[]): voidChildNode.before(...nodes: (Node | string)[]): voidChildNode.before(...nodes: (Node | string)[]): voidInserts nodes just before node, while replacing strings in nodes with equivalent Text nodes. Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. MDN Referenceconst ribbon: ShellPiececonstribbon:ShellPiececonstribbon:ShellPieceReplace the built-in toolbar with an Excel-style ribbon (Home, Insert, Data and View tabs) that narrows its groups as the grid gets narrower. A custom toolbar item list still renders the flat toolbar instead.API reference →RibbonOptions.focusGrid?: (() => void) | undefinedinterfaceRibbonOptions {focusGrid?: (() =>void) |undefined;}interfaceRibbonOptions {focusGrid?:(() =>void) |undefined;}Return keyboard focus to the grid after a pick or Escape (default: focus host).API reference →HTMLOrSVGElement.focus(options?: FocusOptions): voidHTMLOrSVGElement.focus(options?: FocusOptions): voidHTMLOrSVGElement.focus(options?: FocusOptions): voidMDN ReferenceAPI reference →RibbonOptions.onHeightChange?: ((height: number) => void) | undefinedinterfaceRibbonOptions {onHeightChange?: ((height:number) =>void) |undefined;}interfaceRibbonOptions {onHeightChange?:| ((height:number) =>void)|undefined;}Called with the new height after the ribbon is minimized or expanded.API reference →height: numberlet height:numberlet height:numberHost height in CSS pixels for numbers or any CSS length string.API reference →ShellPiece.destroy(): voidShellPiece.destroy(): voidShellPiece.destroy(): voidRuns immediately before a retained element is removed or replaced.API reference →GridConfig.sort?: boolean | undefinedinterfaceGridConfig {sort?:boolean|undefined;}interfaceGridConfig {sort?:boolean|undefined;}Show ascending and descending sort controls in the default toolbar (default true).API reference →GridConfig.export?: boolean | undefinedinterfaceGridConfig {export?:boolean|undefined;}interfaceGridConfig {export?:boolean|undefined;}Show CSV/XLSX export controls in the default toolbar (default false).API reference →GridConfig.toolbar?: boolean | ToolbarItem[] | undefinedinterfaceGridConfig {toolbar?:boolean|ToolbarItem[] |undefined;}interfaceGridConfig {toolbar?:|boolean|ToolbarItem[]|undefined;}Show the built-in toolbar (true), hide it (false), or supply a custom item list.API reference →ToolbarItem.action?: ToolbarActionName | undefinedinterfaceToolbarItem {action?:ToolbarActionName|undefined;}interfaceToolbarItem {action?:ToolbarActionName|undefined;}Built-in action to bind (or "separator"). Omit when supplying onClick.API reference →ToolbarItem.title?: string | undefinedinterfaceToolbarItem {title?:string|undefined;}interfaceToolbarItem {title?:string|undefined;}Accessible tooltip.API reference →ToolbarItem.icon?: ToolbarIcon | undefinedinterfaceToolbarItem {icon?:ToolbarIcon|undefined;}interfaceToolbarItem {icon?:ToolbarIcon|undefined;}Button icon/content. Strings render as plain text; pass a DOM Node or a factory returning one for SVG/HTML icons without using innerHTML.API reference →ToolbarItem.onClick?: ((grid: Grid) => void) | undefinedinterfaceToolbarItem {onClick?: ((grid:Grid) =>void) |undefined;}interfaceToolbarItem {onClick?:| ((grid:Grid) =>void)|undefined;}Custom click handler; receives the grid handle. Overrides action.API reference →grid: Gridlet grid:Gridlet grid:GridThe imperative core grid this controller owns.API reference →Grid.highlightCells(ranges: readonly HighlightRange[] | null, color?: string): voidGrid.highlightCells(ranges: readonly HighlightRange[] |null, color?: string): voidGrid.highlightCells(ranges: readonly HighlightRange[] |null, color?: string): voidDraw temporary highlights outside document history. Pass null to clear all highlights: grid.highlightCells(null). Per-range color wins over the call color. Undo does not clear highlights; use styleRange for persistent cell fills.API reference →const update: (bold: GridCommandState, undo: GridCommandState) => voidconstupdate: (bold:GridCommandState,undo:GridCommandState,) =>voidconstupdate: (bold:GridCommandState,undo:GridCommandState,) =>voidUpdates a retained element after its value, style, theme, or geometry changes.API reference →bold: GridCommandStatelet bold:GridCommandStatelet bold:GridCommandStateUses the bold variant of the theme font.API reference →interface GridCommandStateinterfaceGridCommandStateinterfaceGridCommandStateObservable availability and selection-derived activity for one command.API reference →undo: GridCommandStatelet undo:GridCommandStatelet undo:GridCommandStateUndo the last recorded cell edit. If the restored data is above the transaction resource limits, nothing changes: the Grid emits mutation-rejected and removes that entry, so older edits stay undoable. @example import type { Grid } from "@sheetwrite/core"; function undoAndRestore(grid: Grid) { grid.undo(); grid.redo(); } @see Grid.redoAPI reference →const undoButton: HTMLButtonElementconstundoButton:HTMLButtonElementconstundoButton:HTMLButtonElementHTMLButtonElement.disabled: booleaninterfaceHTMLButtonElement {disabled:boolean;}interfaceHTMLButtonElement {disabled:boolean;}The HTMLButtonElement.disabled property indicates whether the control is disabled, meaning that it does not accept any clicks. MDN ReferenceAPI reference →const boldButton: HTMLButtonElementconstboldButton:HTMLButtonElementconstboldButton:HTMLButtonElementElement.setAttribute(qualifiedName: string, value: string): voidElement.setAttribute(qualifiedName: string, value: string): voidElement.setAttribute(qualifiedName: string, value: string): voidThe setAttribute() method of the Element interface sets the value of an attribute on the specified element. MDN ReferenceGridCommandState.activity: "inactive" | "active" | "mixed"interfaceGridCommandState {activity:"inactive"|"active"|"mixed";}interfaceGridCommandState {activity:|"inactive"|"active"|"mixed";}API reference →var String: StringConstructor
(value?: any) => stringvar String:StringConstructor;(value?:any) => stringvar String:StringConstructor;(value?:any) => stringAllows manipulation and formatting of text strings and determination and location of substrings within strings.GridCommandState.activity: "inactive" | "active"interfaceGridCommandState {activity:"inactive"|"active";}interfaceGridCommandState {activity:"inactive"|"active";}API reference →const stop: () => voidconststop: () =>voidconststop: () =>voidGrid.on<"command-state-change">(evt: "command-state-change", fn: (e: GridCommandStateChangeEvent) => void): () => voidGrid.on<"command-state-change">(evt: "command-state-change", fn: (e:GridCommandStateChangeEvent) =>void): () =>voidGrid.on<"command-state-change">(evt: "command-state-change", fn: (e:GridCommandStateChangeEvent) =>void): () =>voidstates: Readonly<Record<GridCommandName, GridCommandState>>let states:Readonly<Record<GridCommandName, GridCommandState>>let states:Readonly<Record<GridCommandName,GridCommandState>>HTMLButtonElement.addEventListener<"click">(type: "click", listener: (this: HTMLButtonElement, ev: PointerEvent) => any, options?: boolean | AddEventListenerOptions): void (+1 overload)HTMLButtonElement.addEventListener<"click">(type: "click", listener: (this:HTMLButtonElement, ev:PointerEvent) => any, options?: boolean | AddEventListenerOptions): void (+1 overload)HTMLButtonElement.addEventListener<"click">(type: "click", listener: (this:HTMLButtonElement, ev:PointerEvent) => any, options?: boolean | AddEventListenerOptions): void (+1 overload)The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target. MDN Reference The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target. MDN ReferenceGrid.actions: GridActionsinterfaceGrid {actions:GridActions;}interfaceGrid {actions:GridActions;}Imperative action surface for binding custom toolbars/menus.API reference →GridActions.toggleBold(): voidGridActions.toggleBold(): voidGridActions.toggleBold(): voidAPI reference →GridActions.undo(): voidGridActions.undo(): voidGridActions.undo(): voidUndo the last recorded cell edit. If the restored data is above the transaction resource limits, nothing changes: the Grid emits mutation-rejected and removes that entry, so older edits stay undoable. @example import type { Grid } from "@sheetwrite/core"; function undoAndRestore(grid: Grid) { grid.undo(); grid.redo(); } @see Grid.redoAPI reference →