TX Sheet Control

TXSheetControlComponent Class

Class

Angular lifecycle adapter that mounts the editor outside the Angular change-detection zone.

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

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

Constructor

new TXSheetControlComponent(host: ElementRef<HTMLElement>, zone: NgZone, platform: object): TXSheetControlComponent
ParameterTypeOptionalDescription
hosti0.ElementRef<HTMLElement>NoValue matching host's declared type and the owning object's validation rules.
zonei0.NgZoneNoValue matching zone's declared type and the owning object's validation rules.
platformobjectNoValue matching platform's declared type and the owning object's validation rules.

Returns: TXSheetControlComponent.

Members

Properties

PropertyDescription
controlThe control value of TXSheetControlComponent.
exportProgressThe exportProgress value of TXSheetControlComponent.
fileOperationFailedFailed or canceled operations never emit loaded/saved.
initializationErrorReports runtime catalog or font loading failures without emitting a usable control.
loadedSuccessful file operations; saved runs after the output bytes are ready.
loadingCancellable notifications before a file is parsed or an export snapshot is captured.
loadProgressActual processing phases and optional byte/page counts.
optionsEditor options; mutable appearance settings update in place. Mount-only dashboardMode remains fixed until destruction.
readyThe ready value of TXSheetControlComponent.
savedThe saved value of TXSheetControlComponent.
savingThe saving value of TXSheetControlComponent.
workbookChangeThe workbookChange value of TXSheetControlComponent.

Methods

MethodDescription
loadLoads XLSX/TXWB bytes or CSV/XML/JSON text/UTF-8 bytes through the mounted control, preserving its atomic validation and options.
saveSaves through the mounted control with the same reusable options as JavaScript and .NET.
saveTextSaves CSV, XML or JSON text through the initialized editor. Settings, events and UTF-8 limits match save; a generated CSV BOM is omitted.

Examples

Place this standalone component in an Angular application. The ready output initializes invoice data; status outputs report file operations. Buttons call the component load and export methods, and Angular destroys the control with its view.

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

@Component({
    selector: 'app-invoice-editor', standalone: true, imports: [TXSheetControlComponent],
    template: `<tx-sheet-control #sheet style="height:640px" [options]="options"
        (ready)="onReady($event)" (initializationError)="onInitializationError($event)"
        (workbookChange)="status = 'Workbook changed'"
        (loading)="status = 'Loading'" (saving)="status = 'Saving'"
        (loaded)="status = 'Loaded'" (saved)="status = 'Saved'"
        (loadProgress)="status = 'Reading document'" (exportProgress)="status = 'Generating export'"
        (fileOperationFailed)="status = 'Document operation failed'"></tx-sheet-control>
        <input type="file" accept=".xlsx" (change)="loadFile($event)">
        <button [disabled]="!sheet.control" (click)="saveWorkbook()">Download XLSX</button>
        <button [disabled]="!sheet.control" (click)="saveCsv()">Download CSV</button>
        <p role="status">{{status}}</p>`,
})
export class InvoiceEditor {
    @ViewChild(TXSheetControlComponent) sheet!: TXSheetControlComponent;
    options: SpreadsheetOptions = { fontCatalogURL: '/assets/sheet/fonts/catalog.json', theme: 'light' };
    status = 'Starting editor';

    onReady(control: Spreadsheet): void {
        control.workbook.sheets.at(0).range('A1:B3').setValues([
            ['Item', 'Amount'], ['Consulting', 120], ['Training', 80],
        ]);
        this.status = 'Ready';
    }
    onInitializationError(error: unknown): void {
        this.status = error instanceof Error ? error.message : 'Editor could not start';
    }
    async loadFile(event: Event): Promise<void> {
        const file = (event.target as HTMLInputElement).files?.[0];
        if (file && this.sheet.control) await this.sheet.load(new Uint8Array(await file.arrayBuffer()), StreamType.SpreadsheetML);
    }
    async saveWorkbook(): Promise<void> {
        const bytes = await this.sheet.save(StreamType.SpreadsheetML);
        this.download(new Blob([new Uint8Array(bytes)], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }), 'invoice.xlsx');
    }
    async saveCsv(): Promise<void> {
        this.download(new Blob([await this.sheet.saveText(StreamType.CSV)], { type: 'text/csv' }), 'invoice.csv');
    }
    private download(blob: Blob, name: string): void {
        const url = URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = url; link.download = name; link.click();
        setTimeout(() => URL.revokeObjectURL(url), 0);
    }
}

See Also