> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Editor

`@reductoai/xlsx-editor` is a spreadsheet editor for the browser: the Home tab, the editable grid, the formula bar, the sheet tabs, and windows and menus that work like those in Microsoft Excel. One call mounts it.

```ts theme={null}
import { mountXlsxEditor } from "@reductoai/xlsx-editor";
import "@reductoai/xlsx-editor/style.css";

const editor = mountXlsxEditor(document.getElementById("app")!, { workbook: bytes });

const saved: Uint8Array | null = editor.save(); // the .xlsx bytes
editor.open(otherBytes); // open another workbook in the same editor
editor.destroy();
```

The element you pass holds the editor; give it a height.

## Options

| Option | Default | Notes |
| - | - | - |
| `workbook` | none | The bytes of an .xlsx or .xlsm file, or a `Workbook`, to open on mount |
| `fontsUrl` | the npm CDN copy of `@reductoai/portable-fonts` | Your own URL to self-host: copy `node_modules/@reductoai/portable-fonts/files` there |
| `fonts` | the portable fonts at `fontsUrl` | A `FaceProvider` of your own (`tableFaceProvider` from `@reductoai/xlsx/view`) |
| `readOnly` | `false` | Selection, sheets, Find and Copy work; every edit is refused. `model.setReadOnly(on)` changes it later |
| `toolbar` | `true` | The Home tab above the grid |
| `keybindings` | The keys of Microsoft Excel | Changes to the keys |
| `userName` | the workbook's | The name new comments are posted under |
| `hooks` | the browser's `confirm` and `prompt` | `confirmMerge`, `confirmValidation`, `ask` and `afterChange` |
| `side` | none | A task pane right of the grid (below) |

## Commands

`editor.model.run(command)` runs any Home-tab command on the selection, the same commands the toolbar sends. See [Headless editor](https://docs.reducto.ai/office/xlsx/ui/headless-editor.md) for the command list.

```ts theme={null}
import { mountXlsxEditor } from "@reductoai/xlsx-editor";

const editor = mountXlsxEditor(document.getElementById("app")!, { workbook: bytes });
editor.model.run({ type: "toggle", mark: "bold" });
editor.model.run({ type: "undo" });
```

## Task pane

A `side` slot `(host, model) => cleanup` puts a pane right of the grid, under the Home tab, where task panes sit in Microsoft Excel. The host is `display: contents`, so what you append is the pane.

```ts theme={null}
import { mountXlsxEditor } from "@reductoai/xlsx-editor";

mountXlsxEditor(document.getElementById("app")!, {
  workbook: bytes,
  side: (host) => {
    const pane = document.createElement("aside");
    pane.textContent = "Notes";
    host.append(pane);
    return () => pane.remove();
  },
});
```

## Follow changes

The model's fields are Svelte runes. Outside Svelte, `watch(read, onChange)` calls `onChange` when what `read` returns changes. It returns a function that stops watching.

```ts theme={null}
import { mountXlsxEditor, watch } from "@reductoai/xlsx-editor";

const editor = mountXlsxEditor(document.getElementById("app")!, { workbook: bytes });
const stop = watch(
  () => editor.model.canUndo,
  (canUndo) => console.log("can undo:", canUndo),
);
```

## React

```tsx theme={null}
import { useState } from "react";
import { XlsxEditor, useXlsxEditor } from "@reductoai/xlsx-editor/react";
import type { XlsxEditorModel } from "@reductoai/xlsx-editor";
import "@reductoai/xlsx-editor/style.css";

export function App({ bytes }: { bytes: Uint8Array }) {
  const [model, setModel] = useState<XlsxEditorModel | null>(null);
  const canUndo = useXlsxEditor(model, (m) => m?.canUndo ?? false);
  return (
    <>
      <button disabled={!canUndo} onClick={() => model?.run({ type: "undo" })}>
        Undo
      </button>
      <XlsxEditor workbook={bytes} onReady={setModel} style={{ height: 600 }} />
    </>
  );
}
```

`useXlsxEditor(model, select)` re-renders only when the picked value changes (shallow compare). Without a selector it re-renders on every edit, selection and sheet change. `workbook` opens again when it changes, and `readOnly` follows the prop; keep the bytes stable between renders. `side` takes a React node. React is an optional peer dependency.

## Styles

`style.css` styles the editor only: every rule applies under `.reductoai` (the editor's root and its menus). The design tokens all start with `--rd-`. Set a token on `:root` or on any ancestor of the editor to re-skin it; `tokens.css` lists them. For a page that is all editor, also import `page.css`: it styles `html` and `body`.
