TX Sheet Control

TXSheetControlComponent.saved Property

Property

The saved value of TXSheetControlComponent.

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

Syntax

readonly saved: EventEmitter<FileOperationEvent>

Read through the owning object: owner.saved. Follow the declared mutability and owning object lifetime.

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);
    }
}

Remarks

Use this member on an object from the current document. Reacquire document-bound handles after replacement/deletion. Validate arguments against the declared types and documented bounds; handle exceptions or rejected promises.

See Also