Skip to content
Mog is in active development. The GitHub repo, SDK packages, and community channels are not yet available. Follow for launch updates

ws.tables

WorksheetTables

Sub-API for table operations on a worksheet.

53 methods

add

Promise<TableInfo>
add(range: string, options?: TableOptions): Promise<TableInfo>;
ParameterTypeRequired
rangestringrequired
optionsTableOptionsoptional

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>;
ParameterTypeRequired
namestringrequired

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>;
ParameterTypeRequired
indexnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired
columnNamestringrequired

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>;
ParameterTypeRequired
namestringrequired

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>;
ParameterTypeRequired
oldNamestringrequired
newNamestringrequired

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>;
ParameterTypeRequired
tableNamestringrequired
updatesRecord<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>;
ParameterTypeRequired
rownumberrequired
colnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired

Clear all column filters on a table. @param tableName - Table name

setStylePreset

Promise<void>
setStylePreset(tableName: string, preset: string): Promise<void>;
ParameterTypeRequired
tableNamestringrequired
presetstringrequired

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>;
ParameterTypeRequired
namestringrequired
newRangestringrequired

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>;
ParameterTypeRequired
namestringrequired
columnNamestringrequired
positionnumberoptional

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>;
ParameterTypeRequired
namestringrequired
columnIndexnumberrequired

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>;
ParameterTypeRequired
namestringrequired

Toggle the totals row visibility on a table. @param name - Table name

toggleHeaderRow

Promise<void>
toggleHeaderRow(name: string): Promise<void>;
ParameterTypeRequired
namestringrequired

Toggle the header row visibility on a table. @param name - Table name

applyAutoExpansion

Promise<void>
applyAutoExpansion(tableName: string): Promise<void>;
ParameterTypeRequired
tableNamestringrequired

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>;
ParameterTypeRequired
tableNamestringrequired
colIndexnumberrequired
formulastringrequired

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>;
ParameterTypeRequired
tableNamestringrequired
colIndexnumberrequired

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>;
ParameterTypeRequired
namestringrequired

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>;
ParameterTypeRequired
namestringrequired

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>;
ParameterTypeRequired
namestringrequired

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>;
ParameterTypeRequired
tableNamestringrequired
indexnumberoptional
valuesCellValue[]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>;
ParameterTypeRequired
tableNamestringrequired
indexnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired
indicesnumber[]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>;
ParameterTypeRequired
tableNamestringrequired
indexnumberrequired
countnumberoptional

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>;
ParameterTypeRequired
tableNamestringrequired

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>;
ParameterTypeRequired
tableNamestringrequired
indexnumberrequired

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[]>;
ParameterTypeRequired
tableNamestringrequired
indexnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired
indexnumberrequired
valuesCellValue[]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>;
ParameterTypeRequired
tableNamestringrequired
columnIndexnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired
columnIndexnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired
columnIndexnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired
columnIndexnumberrequired

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[]>;
ParameterTypeRequired
tableNamestringrequired
columnIndexnumberrequired

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>;
ParameterTypeRequired
tableNamestringrequired
columnIndexnumberrequired
valuesCellValue[]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>;
ParameterTypeRequired
tableNamestringrequired
valuebooleanrequired

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>;
ParameterTypeRequired
tableNamestringrequired
valuebooleanrequired

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>;
ParameterTypeRequired
tableNamestringrequired
valuebooleanrequired

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>;
ParameterTypeRequired
tableNamestringrequired
valuebooleanrequired

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>;
ParameterTypeRequired
tableNamestringrequired
valuebooleanrequired

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>;
ParameterTypeRequired
tableNamestringrequired
visiblebooleanrequired

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>;
ParameterTypeRequired
tableNamestringrequired
visiblebooleanrequired

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>;
ParameterTypeRequired
tableNamestringrequired
fieldsArray<{ 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>;
ParameterTypeRequired
tableNamestringrequired

Clear all sort fields from a table. @param tableName - Table name

sortReapply

Promise<void>
sortReapply(tableName: string): Promise<void>;
ParameterTypeRequired
tableNamestringrequired

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>;
ParameterTypeRequired
tableNamestringrequired

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>;
ParameterTypeRequired
tableNamestringrequired

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

CallableDisposable
onTableAdded(callback: (event: TableCreatedEvent) => void): CallableDisposable;
ParameterTypeRequired
callback(event: TableCreatedEvent) => voidrequired

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

CallableDisposable
onTableDeleted(callback: (event: TableDeletedEvent) => void): CallableDisposable;
ParameterTypeRequired
callback(event: TableDeletedEvent) => voidrequired

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

CallableDisposable
onTableChanged(
    tableName: string,
    callback: (event: TableUpdatedEvent) => void,
  ): CallableDisposable;
ParameterTypeRequired
tableNamestringrequired
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

CallableDisposable
onSelectionChanged(
    tableName: string,
    callback: (event: TableSelectionChangedEvent) => void,
  ): CallableDisposable;
ParameterTypeRequired
tableNamestringrequired
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