TX Sheet Control

Table Class

Class

A stable operational table handle. Mutations are worksheet-bound and undoable.

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

Related workbook object-model type, returned through the server control. Obtain it from its owning workbook or collection; it is not a required browser-package import.

Constructor

new Table(sheet: Worksheet, id: string): Table
ParameterTypeOptionalDescription
sheetWorksheetNoValue matching sheet's declared type and the owning object's validation rules.
idstringNoStable identity in the owning document/collection.

Returns: Table.

Members

Properties

PropertyDescription
idThe id value of Table.
nameThe name value of Table.
rangeThe range value of Table.
sheetThe sheet value of Table.
snapshotReturns detached current state; throws after deletion or document replacement.

Methods

MethodDescription
deleteColumnsDeletes count columns at a zero-based table-column index, shifting cells left within the table rows. Deleting every column removes the table and invalidates this handle. Invalid bounds, protection and split ranges throw atomically; retained columns keep their identities. This is one undo step.
deleteRowsDeletes count data rows at a zero-based data-row index, shifting cells up within the table columns. Headers and totals are retained; deleting all data rows leaves one empty data row. Invalid bounds, protection and split ranges throw without changing the document. This is one undoable operation.
insertColumnsInserts count columns before a zero-based table-column index (columnCount appends). Shifts cells right within the table rows and creates unique headers. Invalid bounds, protection, split ranges and worksheet overflow throw atomically. Column identities and totals are retained.
insertRowsInserts count data rows before a zero-based data-row index (rowCount appends before totals). Shifts cells down within the table columns; neighboring columns stay intact. Throws for invalid bounds, protected cells, split ranges or worksheet overflow. The worksheet-bound operation is one undo step.
removeConverts the table to ordinary cells; cell content and existing formatting are retained.
renameRenames this table and updates structured references throughout the workbook.
resizeResizes to a non-overlapping range, retaining existing columns and deriving new header names as needed.
setColumnSets a calculated-column formula or totals definition by column name.
updateChanges display options, headers or totals settings while retaining table identity.

Examples

Use a fresh workbook. Create and format the sample data, apply this API and retain the returned document or result in your application. In the browser pass editor.workbook; in Node.js pass the server control.

import type { ServerSheetControl } from '@txtextcontrol/tx-sheet-control-server';

function createTableReport(control: ServerSheetControl) {
    const book = control.workbook;
    const sheet = book.sheets.at(0);
    sheet.cell('A1').setText('October invoice');
    sheet
        .cell('A1')
        .format({
            fontFamily: 'Liberation Sans',
            fontSize: 16,
            bold: true,
            textColor: '#ffffff',
            fillColor: '#163b63',
        });

    sheet.columns.at(0).setWidth({ pixels: 240 });
    sheet.range('B8:B9').setValues([[120], [80]]);
    sheet.cell('B10').setFormula('=SUM(B8:B9)');
    sheet.range('B8:B10').format({ numberFormatCode: '#,##0.00', fontSize: 11 });
    sheet.range('A7:D9').setValues([
        ['Description', 'Quantity', 'UnitPrice', 'Amount'],
        ['Consulting', 3, 120, 360],
        ['Training', 2, 90, 180],
    ]);

    const table = sheet.tables.add('InvoiceLines', 'A7:D9', {
        style: 'TableStyleMedium2',
        hasHeaderRow: true,
        showRowStripes: true,
    });

    table.setColumn('Amount', { formula: '=[@Quantity]*[@UnitPrice]' });
    sheet.range('C8:D9').format({ numberFormatCode: '#,##0.00' });
    return sheet;
}

See Also