# JavaScript

> Run the TX Sheet Control spreadsheet editor in a plain HTML page: copy the browser files, create a Spreadsheet, write cells and a SUM formula or use a bundler.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Getting Started > Spreadsheet Editor > JavaScript
- **2118 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/javascript/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/javascript/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/javascript/llms-full.txt

---

A plain HTML page and a few lines of JavaScript are enough to run the spreadsheet editor of TX Sheet Control in the browser. You copy the editor files into your application, create the editor in a `div` element and fill the first worksheet with values and a formula. No server package is needed.

The editor comes in two forms: the editor npm archive and the standalone files in the release's `browser` folder. Both include XLSX and PDF, charts, dashboards and fonts. The steps below use the standalone files, and [Use npm With a Bundler](#use-npm-with-a-bundler) describes what changes with the npm package.

### Copy the Editor Files

Copy the supplied `browser` folder into your application's `sheet` static folder, with its fonts, languages and notices. Keep the relative asset folders intact, so that the font and language requests of the editor resolve.

To use the npm archive instead, install it as described in [Install the npm Packages](https://docs.textcontrol.com/tx-sheet-control/installation/npm/llms-full.txt).

### Create the HTML Page

Create `index.html`:

```html
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Sales workbook</title>
</head>
<body>
    <div id="sheet" style="height:720px"></div>
    <script src="./sheet/tx-sheet-control.min.js"></script>
    <script src="./main.js"></script>
</body>
</html>
```

The page loads the editor and provides its host:

- The `div` with the ID `sheet` is the host element of the editor. The editor needs a visible host with a nonzero width and height, so the `div` is 720 pixels high.
- The first `script` element loads the editor, `tx-sheet-control.min.js`. The second loads `main.js`, your code.

### Write the Code

In `main.js`:

```javascript
async function start() {
    const { Spreadsheet } = TXTextControl.TXSheetControl;
    const editor = new Spreadsheet(document.getElementById('sheet'), {
    license: 'YOUR_SIGNED_LICENSE',
        fontCatalogURL: './sheet/fonts/catalog.json', locale: 'en-US', currency: 'USD'
    });

    await editor.ready;

    const sheet = editor.workbook.sheets.at(0);
    sheet.range('A1:B3').setValues([
        ['Item', 'Amount'], ['Hardware', 120], ['Software', 80]
    ]);

    sheet.cell('B4').setFormula('=SUM(B2:B3)');
    window['salesEditor'] = editor;
}

start().catch(error => console.error(error));
```

The code works as follows:

- The code takes the [Spreadsheet](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/llms-full.txt) class from the global `TXTextControl.TXSheetControl` object of the standalone script.
- `new Spreadsheet()` creates the editor in the `sheet` element. The second argument holds the options, which the [SpreadsheetOptions](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/spreadsheetoptions/llms-full.txt) interface of the TypeScript reference describes. [fontCatalogURL](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/spreadsheetoptions/fontcatalogurl-property/llms-full.txt) is the URL of the font catalog in the copied folder; without it, plain JavaScript looks for the catalog at `/sheet-fonts/catalog.json`. [locale](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/spreadsheetoptions/locale-property/llms-full.txt) is `en-US` and [currency](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/spreadsheetoptions/currency-property/llms-full.txt) is `USD`.
- `await editor.ready` waits for [ready](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/ready-property/llms-full.txt), which resolves after discovery, font-picker initialization and the initial document fonts, and rejects on failure.
- [workbook](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/workbook-property/llms-full.txt), [sheets](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/workbook/sheets-property/llms-full.txt) and [at](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/sheetcollection/at-method/llms-full.txt) return the first worksheet. The index is zero-based.
- [range](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/range-method/llms-full.txt) and [setValues](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/range/setvalues-method/llms-full.txt) write the headings `Item` and `Amount` and two items into A1:B3. The array has the dimensions of the range, one inner array per row.
- [cell](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/cell-method/llms-full.txt) and [setFormula](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/cell/setformula-method/llms-full.txt) put the formula `=SUM(B2:B3)` into B4. The leading equals sign is required.
- `window['salesEditor'] = editor` stores the editor in the global variable `salesEditor`.
- `start().catch()` writes any error, such as a rejected `ready`, to the console.

### Run the Page

Serve the page through HTTP and open it. The value of B4 is 200, the sum of 120 and 80.

> Important
>
> **Serve the Page Through HTTP.** Opening `index.html` as a file, with a `file://` address, does not provide the normal asset-fetch behavior.

Configure `license` with the contents of your license file, `tx-sheet-control.license`, before creating the editor. See [Licensing](https://docs.textcontrol.com/tx-sheet-control/deployment/licensing/llms-full.txt) for the Trial, Developer and OEM options.

### Use npm With a Bundler

With the editor npm package and a bundler, the steps differ from the script-based page:

1. Import `Spreadsheet` and [StreamType](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/streamtype/llms-full.txt) from `@txtextcontrol/tx-sheet-control`. `StreamType` selects the file format when you load and save a workbook.
2. The imported editor installs its bundled styles inside Shadow DOM automatically; no global editor stylesheet is required.
3. Copy `dist/fonts` and `dist/languages` to your public assets, and set [fontBaseURL](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/spreadsheetoptions/fontbaseurl-property/llms-full.txt) or `fontCatalogURL` for their deployed location.

Create one editor per host element, await `ready` before you use it and call [destroy](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/destroy-method/llms-full.txt) when you remove it. The call `destroy()` takes no arguments.

### Next Steps

- [TypeScript](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/typescript/llms-full.txt): create the editor in a TypeScript module with typed options and save the workbook as XLSX.
- [Loading and Saving Workbooks](https://docs.textcontrol.com/tx-sheet-control/document-processing/load-save/llms-full.txt): load and save XLSX, TXWB, PDF, CSV, XML and JSON with `StreamType`.
- [Font Handling](https://docs.textcontrol.com/tx-sheet-control/deployment/fonts/llms-full.txt): find out how fonts affect the layout and the PDF output, and how the included fonts are deployed.
- [Static Assets and Offline Hosting](https://docs.textcontrol.com/tx-sheet-control/deployment/static-assets/llms-full.txt): serve the script, fonts and languages from your own paths.

Before running the example, replace `YOUR_SIGNED_LICENSE` with the contents of your license file, `tx-sheet-control.license`, which the Text Control Account issues for your Trial, Developer or OEM serial number.

### Isolated Editor Styles

The editor mounts its complete UI in an open Shadow DOM and installs its bundled styles automatically. No global editor stylesheet is required. Bootstrap and other application styles cannot select internal dialogs, ribbon controls, menus or worksheet overlays. Give the host its size and use the public UI API for theme, language, ribbon and area settings.

Workbook APIs, editor APIs, `ready` and host events work as usual. DOM selectors on the page do not search editor internals. If an integration deliberately inspects internal elements, start at `host.shadowRoot`; internal markup is not the application API. Destroying the editor clears its owned shadow content and styles. The same host can then be initialized again.

---

## Nearby

- **Previous:** [Spreadsheet Editor](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/llms-full.txt)
- **Next:** [TypeScript](https://docs.textcontrol.com/tx-sheet-control/getting-started/spreadsheet-editor/typescript/llms-full.txt)
