> ## 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.

# View

`@reductoai/xlsx/view` paints a workbook on a canvas in the browser: cells, merged cells, conditional formats, charts, pictures, frozen panes and the sheet tabs.

```ts theme={null}
import { Workbook } from "@reductoai/xlsx";
import { browserDrawingHost, portableFaceProvider, previewWorkbook, setDrawingHost } from "@reductoai/xlsx/view";

setDrawingHost(browserDrawingHost(portableFaceProvider((file) => `/fonts/${file}`)));

const wb = Workbook.open(bytes);
const view = previewWorkbook(document.getElementById("grid")!, wb, { initialSheet: "Summary" });
```

Install the drawing host once, before the first view. `portableFaceProvider` loads the portable fonts from the URL you give for each file; copy `node_modules/@reductoai/portable-fonts/files` to your site (see [Fonts](https://docs.reducto.ai/office/xlsx/getting-started/fonts.md)).

## Options

| Option | Notes |
| - | - |
| `initialSheet` | Sheet name or zero-based index to show first |
| `initialZoom` | Zoom to start at |
| `showHidden` | Show hidden sheets in the tabs |
| `editable` | Typing, F2, Delete, undo and redo edit the cells |
| `readOnly` | With `editable`: selection, Find and Copy work, every edit is refused |

## Edits from code

After you change the workbook from code, call `view.refresh()`.

```ts theme={null}
import { Workbook } from "@reductoai/xlsx";
import { previewWorkbook } from "@reductoai/xlsx/view";

const wb = Workbook.open(bytes);
const view = previewWorkbook(document.getElementById("grid")!, wb, { editable: true });
view.on("edit", () => console.log("edited"));
wb.getSheet("Summary")!.setValue(0, 0, "New title");
view.refresh();
```

Call `view.destroy()` when you remove the element.

## Picture of a range

`view.rangeImage(range, options)` returns a PNG `Blob` of a range, as Excel's Copy Picture shows it. It does not show the selection, and it shows headers and gridlines only when you ask (`labels`, `gridlines`). With no range, the picture shows the selected cells.

```ts theme={null}
import { Workbook } from "@reductoai/xlsx";
import { previewWorkbook } from "@reductoai/xlsx/view";

const view = previewWorkbook(document.getElementById("grid")!, Workbook.open(bytes));
const png = await view.rangeImage("Summary!A1:H30", { scale: 2 });
```

In the [editor](https://docs.reducto.ai/office/xlsx/ui/editor.md), the view is `editor.model.view`. See [PNG](https://docs.reducto.ai/office/xlsx/rendering/png.md#in-the-browser-from-a-view) for the options and limits.

> [!TIP]
>
> For a full spreadsheet UI with the Home tab, menus and windows, use [`@reductoai/xlsx-editor`](https://docs.reducto.ai/office/xlsx/ui/editor) instead. It sets up the fonts for you.
