# WorkbookEvents Class

> WorkbookEvents class in the TX Sheet Control TypeScript API for the browser: Per-document typed subscriptions. Covers 2 methods and a TypeScript example.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Class
- **Path:** TX Sheet Control > API Reference > TypeScript API > Browser Editor > WorkbookEvents Class
- **618 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/llms-full.txt

---

Per-document typed subscriptions. Callbacks are excluded from saved state and undo history.

Package: `@txtextcontrol/tx-sheet-control`. Version: **2.0.0**.

ES module import: `import { WorkbookEvents } from '@txtextcontrol/tx-sheet-control';`.

### Constructor

```typescript
new WorkbookEvents(): WorkbookEvents
```

This overload has no parameters.

Returns: `WorkbookEvents`.

### Members

#### Methods

| Method | Description |
|---|---|
| [on](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/on-method/llms-full.txt) | Registers a listener and returns an idempotent unsubscribe function. |
| [once](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/once-method/llms-full.txt) | Registers a listener that unsubscribes before its first invocation. |

### Examples

Use a fresh workbook. Create and format the sample data, apply this API and retain the returned document or result in your application. In the browser pass editor.workbook; in Node.js pass the server control.

```typescript
import type { Workbook } from '@txtextcontrol/tx-sheet-control';

function createWorkbookEventsReport(book: Workbook) {
    const sheet = book.sheets.at(0);
    const changes: string[] = [];
    const unsubscribe = book.events.on('changed', (event) => changes.push(JSON.stringify(event)));

    try {
        sheet.cell('A1').setText('October invoice');
        sheet
            .cell('A1')
            .format({
                fontFamily: 'Liberation Sans',
                fontSize: 16,
                bold: true,
                textColor: '#ffffff',
                fillColor: '#163b63',
            });

        sheet.columns.at(0).setWidth({ pixels: 240 });
    } finally {
        unsubscribe();
    }

    return changes;
}
```

### See Also

- [TypeScript Browser Editor API](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/llms-full.txt)
- [Events and Cancellation](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/events/llms-full.txt)

---

## In This Section

- [WorkbookEvents.on Method](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/on-method/llms-full.txt): WorkbookEvents.on method in the TX Sheet Control TypeScript API for the browser: Registers a listener and returns an idempotent unsubscribe function.
- [WorkbookEvents.once Method](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/once-method/llms-full.txt): WorkbookEvents.once method in the TX Sheet Control TypeScript API for the browser: Registers a listener that unsubscribes before its first invocation.

---

## Nearby

- **Previous:** [WorkbookEventMap.validationFailed Property](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookeventmap/validationfailed-property/llms-full.txt)
- **Next:** [WorkbookEvents.on Method](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/workbookevents/on-method/llms-full.txt)
