ws.tables
WorksheetTables
Sub-API for table operations on a worksheet.
53 methods
add
→ Promise<TableInfo>add(range: string, options?: TableOptions): Promise<TableInfo>;| Parameter | Type | Required |
|---|---|---|
| range | string | required |
| options | TableOptions | optional |
Create a new table from a cell range. @param range - A1-style range string (e.g. "A1:D10") @param options - Optional table creation settings (name, headers, style) @returns The created table information
get
→ Promise<TableInfo | null>get(name: string): Promise<TableInfo | null>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get a table by name. Tables are workbook-scoped, so the name is unique across all sheets. @param name - Table name @returns Table information, or null if not found
list
→ Promise<TableInfo[]>list(): Promise<TableInfo[]>;List all tables in this worksheet. @returns Array of table information objects
getAt
→ Promise<TableInfo | null>getAt(index: number): Promise<TableInfo | null>;| Parameter | Type | Required |
|---|---|---|
| index | number | required |
Get a table by its position in the list of tables on this worksheet. @param index - Zero-based index into the table list @returns Table information, or null if the index is out of range
getFirst
→ Promise<TableInfo | null>getFirst(): Promise<TableInfo | null>;Get the first table on this worksheet. Convenience shortcut equivalent to `getAt(0)`. @returns Table information, or null if no tables exist
getColumnByName
→ Promise<TableColumn | null>getColumnByName(tableName: string, columnName: string): Promise<TableColumn | null>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| columnName | string | required |
Look up a column in a table by its header name. @param tableName - Table name @param columnName - Column header name to search for @returns The matching column, or null if not found
remove
→ Promise<TableRemoveReceipt>remove(name: string): Promise<TableRemoveReceipt>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Remove a table definition, converting it back to a plain range. Cell data is preserved; only the table metadata is removed. @param name - Table name
rename
→ Promise<void>rename(oldName: string, newName: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| oldName | string | required |
| newName | string | required |
Rename a table. @param oldName - Current table name @param newName - New table name
update
→ Promise<void>update(tableName: string, updates: Record<string, any>): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| updates | Record<string, any> | required |
Update a table's properties. @param tableName - Table name @param updates - Key-value pairs of properties to update
getAtCell
→ Promise<TableInfo | null>getAtCell(row: number, col: number): Promise<TableInfo | null>;| Parameter | Type | Required |
|---|---|---|
| row | number | required |
| col | number | required |
Get the table at a specific cell position, if one exists. @param row - Row index (0-based) @param col - Column index (0-based) @returns Table information, or null if no table exists at that cell
clearFilters
→ Promise<void>clearFilters(tableName: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
Clear all column filters on a table. @param tableName - Table name
setStylePreset
→ Promise<void>setStylePreset(tableName: string, preset: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| preset | string | required |
Set the visual style preset for a table. @param tableName - Table name @param preset - Style preset name (e.g. "TableStyleLight1")
resize
→ Promise<TableResizeReceipt>resize(name: string, newRange: string): Promise<TableResizeReceipt>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
| newRange | string | required |
Resize a table to a new range. @param name - Table name @param newRange - New A1-style range string
addColumn
→ Promise<TableAddColumnReceipt>addColumn(name: string, columnName: string, position?: number): Promise<TableAddColumnReceipt>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
| columnName | string | required |
| position | number | optional |
Add a column to a table. @param name - Table name @param columnName - Name for the new column @param position - Column position (0-based index). If omitted, appends to the end.
removeColumn
→ Promise<TableRemoveColumnReceipt>removeColumn(name: string, columnIndex: number): Promise<TableRemoveColumnReceipt>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
| columnIndex | number | required |
Remove a column from a table by index. @param name - Table name @param columnIndex - Column index within the table (0-based)
toggleTotalsRow
→ Promise<void>toggleTotalsRow(name: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Toggle the totals row visibility on a table. @param name - Table name
toggleHeaderRow
→ Promise<void>toggleHeaderRow(name: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Toggle the header row visibility on a table. @param name - Table name
applyAutoExpansion
→ Promise<void>applyAutoExpansion(tableName: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
Apply auto-expansion to a table, extending it to include adjacent data. @param tableName - Table name
setCalculatedColumn
→ Promise<void>setCalculatedColumn(tableName: string, colIndex: number, formula: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| colIndex | number | required |
| formula | string | required |
Set a calculated column formula for all data cells in a table column. @param tableName - Table name @param colIndex - Column index within the table (0-based) @param formula - The formula to set (e.g. "=[@Price]*[@Quantity]")
clearCalculatedColumn
→ Promise<void>clearCalculatedColumn(tableName: string, colIndex: number): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| colIndex | number | required |
Clear the calculated column formula from a table column, replacing with empty values. @param tableName - Table name @param colIndex - Column index within the table (0-based)
getDataBodyRange
→ Promise<string | null>getDataBodyRange(name: string): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get the A1-notation range covering the data body of a table (excludes header and totals rows). @param name - Table name @returns A1-notation range string, or null if the table has no data body rows
getHeaderRowRange
→ Promise<string | null>getHeaderRowRange(name: string): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get the A1-notation range covering the header row of a table. @param name - Table name @returns A1-notation range string, or null if the table has no header row
getTotalRowRange
→ Promise<string | null>getTotalRowRange(name: string): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get the A1-notation range covering the totals row of a table. @param name - Table name @returns A1-notation range string, or null if the table has no totals row
addRow
→ Promise<TableAddRowReceipt>addRow(tableName: string, index?: number, values?: CellValue[]): Promise<TableAddRowReceipt>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| index | number | optional |
| values | CellValue[] | optional |
Add a data row to a table. @param tableName - Table name @param index - Row index within the data body (0-based). If omitted, appends to the end. @param values - Optional cell values for the new row
deleteRow
→ Promise<TableDeleteRowReceipt>deleteRow(tableName: string, index: number): Promise<TableDeleteRowReceipt>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| index | number | required |
Delete a data row from a table. @param tableName - Table name @param index - Row index within the data body (0-based)
deleteRows
→ Promise<void>deleteRows(tableName: string, indices: number[]): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| indices | number[] | required |
Delete multiple data rows from a table by their data-body-relative indices. Rows are deleted in descending index order to avoid index shifting. @param tableName - Table name @param indices - Array of row indices within the data body (0-based)
deleteRowsAt
→ Promise<void>deleteRowsAt(tableName: string, index: number, count?: number): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| index | number | required |
| count | number | optional |
Delete one or more contiguous data rows from a table starting at `index`. @param tableName - Table name @param index - Starting row index within the data body (0-based) @param count - Number of rows to delete (default 1)
getRowCount
→ Promise<number>getRowCount(tableName: string): Promise<number>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
Get the number of data rows in a table (excludes header and totals rows). @param tableName - Table name @returns Number of data rows
getRowRange
→ Promise<string>getRowRange(tableName: string, index: number): Promise<string>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| index | number | required |
Get the A1-notation range for a specific data row. @param tableName - Table name @param index - Row index within the data body (0-based) @returns A1-notation range string
getRowValues
→ Promise<CellValue[]>getRowValues(tableName: string, index: number): Promise<CellValue[]>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| index | number | required |
Get the cell values of a specific data row. @param tableName - Table name @param index - Row index within the data body (0-based) @returns Array of cell values
setRowValues
→ Promise<void>setRowValues(tableName: string, index: number, values: CellValue[]): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| index | number | required |
| values | CellValue[] | required |
Set the cell values of a specific data row. @param tableName - Table name @param index - Row index within the data body (0-based) @param values - Cell values to set
getColumnDataBodyRange
→ Promise<string | null>getColumnDataBodyRange(tableName: string, columnIndex: number): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| columnIndex | number | required |
Get the A1-notation range covering the data body cells of a table column. @param tableName - Table name @param columnIndex - Column index within the table (0-based) @returns A1-notation range string, or null if no data body rows
getColumnHeaderRange
→ Promise<string | null>getColumnHeaderRange(tableName: string, columnIndex: number): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| columnIndex | number | required |
Get the A1-notation range covering the header cell of a table column. @param tableName - Table name @param columnIndex - Column index within the table (0-based) @returns A1-notation range string, or null if no header row
getColumnRange
→ Promise<string | null>getColumnRange(tableName: string, columnIndex: number): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| columnIndex | number | required |
Get the A1-notation range covering the entire table column (header + data + totals). @param tableName - Table name @param columnIndex - Column index within the table (0-based) @returns A1-notation range string, or null if column does not exist
getColumnTotalRange
→ Promise<string | null>getColumnTotalRange(tableName: string, columnIndex: number): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| columnIndex | number | required |
Get the A1-notation range covering the totals cell of a table column. @param tableName - Table name @param columnIndex - Column index within the table (0-based) @returns A1-notation range string, or null if no totals row
getColumnValues
→ Promise<CellValue[]>getColumnValues(tableName: string, columnIndex: number): Promise<CellValue[]>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| columnIndex | number | required |
Get the cell values of a table column (data body only). @param tableName - Table name @param columnIndex - Column index within the table (0-based) @returns Array of cell values
setColumnValues
→ Promise<void>setColumnValues(tableName: string, columnIndex: number, values: CellValue[]): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| columnIndex | number | required |
| values | CellValue[] | required |
Set the cell values of a table column (data body only). @param tableName - Table name @param columnIndex - Column index within the table (0-based) @param values - Cell values to set
setHighlightFirstColumn
→ Promise<void>setHighlightFirstColumn(tableName: string, value: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| value | boolean | required |
Set whether the first column is highlighted. @param tableName - Table name @param value - Whether to highlight the first column
setHighlightLastColumn
→ Promise<void>setHighlightLastColumn(tableName: string, value: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| value | boolean | required |
Set whether the last column is highlighted. @param tableName - Table name @param value - Whether to highlight the last column
setShowBandedColumns
→ Promise<void>setShowBandedColumns(tableName: string, value: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| value | boolean | required |
Set whether banded columns are shown. @param tableName - Table name @param value - Whether to show banded columns
setShowBandedRows
→ Promise<void>setShowBandedRows(tableName: string, value: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| value | boolean | required |
Set whether banded rows are shown. @param tableName - Table name @param value - Whether to show banded rows
setShowFilterButton
→ Promise<void>setShowFilterButton(tableName: string, value: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| value | boolean | required |
Set whether filter buttons are shown on the header row. @param tableName - Table name @param value - Whether to show filter buttons
setShowHeaders
→ Promise<void>setShowHeaders(tableName: string, visible: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| visible | boolean | required |
Set whether the header row is visible. @param tableName - Table name @param visible - Whether to show the header row
setShowTotals
→ Promise<void>setShowTotals(tableName: string, visible: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| visible | boolean | required |
Set whether the totals row is visible. @param tableName - Table name @param visible - Whether to show the totals row
sortApply
→ Promise<void>sortApply(
tableName: string,
fields: Array<{ columnIndex: number; ascending?: boolean }>,
): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| fields | Array<{ columnIndex: number; ascending?: boolean }> | required |
Apply sort fields to a table. @param tableName - Table name @param fields - Array of sort field descriptors
sortClear
→ Promise<void>sortClear(tableName: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
Clear all sort fields from a table. @param tableName - Table name
sortReapply
→ Promise<void>sortReapply(tableName: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
Re-evaluate the most recently applied sort specification. Throws if no sort specification has been applied via `sortApply`. @param tableName - Table name
getAutoFilter
→ Promise<FilterInfo | null>getAutoFilter(tableName: string): Promise<FilterInfo | null>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
Get the auto-filter associated with a table. @param tableName - Table name @returns Filter information, or null if the table has no associated filter
getRows
→ Promise<TableRowCollection>getRows(tableName: string): Promise<TableRowCollection>;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
Get a collection-like wrapper around the table's data rows. The returned object delegates to the existing row methods on this API. The `count` property is a snapshot taken at call time and does not live-update. @param tableName - Table name @returns A TableRowCollection object
onTableAdded
→ CallableDisposableonTableAdded(callback: (event: TableCreatedEvent) => void): CallableDisposable;| Parameter | Type | Required |
|---|---|---|
| callback | (event: TableCreatedEvent) => void | required |
Subscribe to table creation events on this worksheet. Fires when a new table is added to this worksheet. @param callback - Handler invoked with the TableCreatedEvent @returns A disposable that unsubscribes the handler when disposed
onTableDeleted
→ CallableDisposableonTableDeleted(callback: (event: TableDeletedEvent) => void): CallableDisposable;| Parameter | Type | Required |
|---|---|---|
| callback | (event: TableDeletedEvent) => void | required |
Subscribe to table deletion events on this worksheet. Fires when a table is removed from this worksheet. @param callback - Handler invoked with the TableDeletedEvent @returns A disposable that unsubscribes the handler when disposed
onTableChanged
→ CallableDisposableonTableChanged(
tableName: string,
callback: (event: TableUpdatedEvent) => void,
): CallableDisposable;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| callback | (event: TableUpdatedEvent) => void, | required |
Subscribe to change events for a specific table. Fires when the table's structure or properties are updated (e.g. columns added/removed, style changed, renamed, resized, totals toggled, etc.). @param tableName - The name of the table to observe @param callback - Handler invoked with the TableUpdatedEvent @returns A disposable that unsubscribes the handler when disposed
onSelectionChanged
→ CallableDisposableonSelectionChanged(
tableName: string,
callback: (event: TableSelectionChangedEvent) => void,
): CallableDisposable;| Parameter | Type | Required |
|---|---|---|
| tableName | string | required |
| callback | (event: TableSelectionChangedEvent) => void, | required |
Subscribe to selection change events for a specific table. Fires when the user's selection enters, moves within, or leaves the table. Note: events are only emitted once the selection machine is wired to emit `table:selection-changed`; until then the subscription is inert. @param tableName - The name of the table to observe @param callback - Handler invoked with the TableSelectionChangedEvent @returns A disposable that unsubscribes the handler when disposed