TXSheetControlComponent 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
| Parameter | Type | Optional | Description |
|---|---|---|---|
host | i0.ElementRef<HTMLElement> | No | Value matching host's declared type and the owning object's validation rules. |
zone | i0.NgZone | No | Value matching zone's declared type and the owning object's validation rules. |
platform | object | No | Value matching platform's declared type and the owning object's validation rules. |
Returns: TXSheetControlComponent.
Members
Properties
| Property | Description |
|---|---|
| control | The control value of TXSheetControlComponent. |
| exportProgress | The exportProgress value of TXSheetControlComponent. |
| fileOperationFailed | Failed or canceled operations never emit loaded/saved. |
| initializationError | Reports runtime catalog or font loading failures without emitting a usable control. |
| loaded | Successful file operations; saved runs after the output bytes are ready. |
| loading | Cancellable notifications before a file is parsed or an export snapshot is captured. |
| loadProgress | Actual processing phases and optional byte/page counts. |
| options | Editor options; mutable appearance settings update in place. Mount-only dashboardMode remains fixed until destruction. |
| ready | The ready value of TXSheetControlComponent. |
| saved | The saved value of TXSheetControlComponent. |
| saving | The saving value of TXSheetControlComponent. |
| workbookChange | The workbookChange value of TXSheetControlComponent. |
Methods
| Method | Description |
|---|---|
| load | Loads XLSX/TXWB bytes or CSV/XML/JSON text/UTF-8 bytes through the mounted control, preserving its atomic validation and options. |
| save | Saves through the mounted control with the same reusable options as JavaScript and .NET. |
| saveText | Saves 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';
({
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 {
(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);
}
}