Table 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
| Parameter | Type | Optional | Description |
|---|---|---|---|
sheet | Worksheet | No | Value matching sheet's declared type and the owning object's validation rules. |
id | string | No | Stable identity in the owning document/collection. |
Returns: Table.
Members
Properties
| Property | Description |
|---|---|
| id | The id value of Table. |
| name | The name value of Table. |
| range | The range value of Table. |
| sheet | The sheet value of Table. |
| snapshot | Returns detached current state; throws after deletion or document replacement. |
Methods
| Method | Description |
|---|---|
| deleteColumns | Deletes 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. |
| deleteRows | Deletes 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. |
| insertColumns | Inserts 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. |
| insertRows | Inserts 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. |
| remove | Converts the table to ordinary cells; cell content and existing formatting are retained. |
| rename | Renames this table and updates structured references throughout the workbook. |
| resize | Resizes to a non-overlapping range, retaining existing columns and deriving new header names as needed. |
| setColumn | Sets a calculated-column formula or totals definition by column name. |
| update | Changes 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;
}