TX Sheet Control

Angular

Topic

TXSheetControlComponent brings the spreadsheet editor into an Angular application. You bind options to it, receive the editor in its ready output and work with the workbook through the same API as in JavaScript.

Install the Package

The Angular integration is included in the editor package @txtextcontrol/tx-sheet-control: you import it from @txtextcontrol/tx-sheet-control/angular, and there is no separate Angular package. Install the editor package as described in Install the npm Packages. The component requires Angular 22.

Add the Component

The following standalone component, AppComponent with the selector app-root, shows the editor and fills its first worksheet as soon as the editor is ready:

import { Component } from '@angular/core';
import { TXSheetControlComponent } from '@txtextcontrol/tx-sheet-control/angular';
import { type Spreadsheet, type SpreadsheetOptions } from '@txtextcontrol/tx-sheet-control';

@Component({
    selector: 'app-root', standalone: true,
    imports: [TXSheetControlComponent],
    template: `<tx-sheet-control [options]="options" (ready)="onReady($event)"
        (initializationError)="onError($event)" style="height:640px" />`
})
export class AppComponent {
    options: SpreadsheetOptions = { license: 'YOUR_SIGNED_LICENSE', locale: 'en-US', height: 'fill', fontCatalogURL: '/assets/sheet/fonts/catalog.json' };
    onReady(editor: Spreadsheet): void {
        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)');
    }

    onError(error: unknown): void { console.error(error); }
}

The code works as follows:

  • TXSheetControlComponent comes from @txtextcontrol/tx-sheet-control/angular and is listed in imports. Its element in the template is tx-sheet-control. The component mounts the editor outside the Angular change-detection zone.
  • [options] binds the options input to a SpreadsheetOptions object: locale is en-US, height is 'fill' and fontCatalogURL is the URL of the deployed font catalog.
  • The style attribute gives the element a definite height of 640 pixels.
  • ready emits the editor, a Spreadsheet, to onReady. There, workbook, sheets and at return the first worksheet.
  • range and setValues write the headings Item and Amount and two items into A1:B3, and cell and setFormula put the formula =SUM(B2:B3) into B4.
  • initializationError reports runtime catalog or font loading failures without emitting a usable control. onError writes the error to the console.
  • Spreadsheet and SpreadsheetOptions are imported as types from @txtextcontrol/tx-sheet-control.

Deploy the Assets and Set a Height

  1. The editor installs its bundled stylesheet inside its own Shadow DOM automatically; do not add a global editor stylesheet.
  2. Copy dist/fonts and dist/languages into your static assets. If the deployed paths differ, configure the asset base and the catalog in the options, with fontBaseURL and fontCatalogURL.
  3. Give the component and its parent layout a definite height. A height of 100% needs a parent with a known height.

How the Component Lifetime Works

The component mounts in the browser and releases its editor on destruction. Server-side page rendering does not create a browser editor.

Important

Wait for Ready. control, the editor of the component, is undefined before mounting. Use (ready) instead of assuming that the control exists during construction.

Mutable appearance settings in the options can update in place. The hosting policy dashboardMode is fixed for the mounted control's lifetime: to change that policy, recreate the component.

React to Events

The outputs of the component cover ready and error, workbook changes, loading and saving, loaded and saved files, progress and failures:

OutputReports
ready, initializationErrorThe editor is ready, or its initialization failed
workbookChangeA change of the workbook
loading, savingA file is about to be parsed or an export snapshot captured; you can cancel the operation
loaded, savedA file operation succeeded; saved follows once the output bytes are ready
loadProgress, exportProgressThe actual processing phases, with optional byte and page counts
fileOperationFailedA failed or canceled operation, which never emits loaded or saved

Use the control for the same workbook APIs as JavaScript, and await file operations such as load and save. Application data retrieval remains the host's responsibility.

Next Steps

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.