Word.Table
Word.Table is an object type of the Word module (Office.word(iframe)). 22 methods.
Word · 14 object types · 259 methods · namespace Word. This reference is generated from the API document artifact (sdk-api-doc.html) produced with the SDK build. Descriptions are the editor's API comments as published. Pin the SDK and Office versions together and regenerate when either changes.
Remarks
- Module: Word ·
Office.word(iframe)· namespaceWord - Obtained from:
Document.getTable(tableId),Body.insertTable(rows, columns, options),Paragraph.getParentTable(),Paragraph.insertTable(rows, columns, options),Range.insertTable(rows, columns, options),TableRow.getTable(),TableCell.getTable() - Every method returns a
Promise; signatures use TypeScript notation.
Methods
| Method | Description |
|---|---|
delete() | Deletes the table. |
deleteColumn(columnIndex) | Deletes a column. |
deleteRow(rowIndex) | Deletes a row. |
distributeColumns(range) | Makes the widths of the target columns equal. |
getCell(rowIndex, columnIndex) | Returns the cell at the given position. |
getColumnCount() | Returns the total number of columns in the table, including the columns occupied by merged cells. |
getId() | Returns the table ID. |
getRow(rowIndex) | Returns the row at the given position. |
getRowCount() | Returns the number of rows in the table. |
insertColumn(columnIndex, position) | Inserts a new column to the left or right of the reference column. |
insertRow(rowIndex, position) | Inserts a new row before or after the reference row. |
mergeCells(range) | Merges a cell range. |
setAlignment(align) | Sets the horizontal position of the table within the page. |
setCellBackgroundColor(range, color) | Sets the background color of a cell range. |
setCellBorder(range, border) | Sets the borders of a cell range. |
setCellPadding(range, padding) | Sets the inner padding of the given cell range. |
setCellVerticalAlignment(range, align) | Sets the vertical alignment of a cell range. |
setColumnWidths(widths) | Sets the widths of all columns in the table. |
setRowHeight(height, range) | Sets the target rows to the same given height. |
setRowHeights(heights) | Sets the row heights of the table row by row. |
setValues(values) | Replaces the content of multiple cells with text from a 2D array. |
unmergeCells(range) | Splits the merged cells within the given range. |
Method details
delete()
Deletes the table.
delete(): Promise<void>;
Returns
Promise<void>
deleteColumn(columnIndex)
Deletes a column.
deleteColumn(columnIndex: number): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
columnIndex | number | index of the column to delete (0-based) |
Returns
Promise<void>
deleteRow(rowIndex)
Deletes a row.
deleteRow(rowIndex: number): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
rowIndex | number | index of the row to delete (0-based) |
Returns
Promise<void>
distributeColumns(range)
Makes the widths of the target columns equal. - Divides the total width of the target columns evenly while preserving it; other columns are unchanged.
distributeColumns(range?: CellRange): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
range (optional) | CellRange | target column range. Only the column span (col/colSpan) is used (default: whole table) |
Returns
Promise<void>
getCell(rowIndex, columnIndex)
Returns the cell at the given position.
getCell(rowIndex: number, columnIndex: number): Promise<TableCell>;
Parameters
| Name | Type | Description |
|---|---|---|
rowIndex | number | row index (0-based) |
columnIndex | number | column index (0-based) |
Returns
Promise<TableCell> - the cell at that row and column
getColumnCount()
Returns the total number of columns in the table, including the columns occupied by merged cells.
getColumnCount(): Promise<number>;
Returns
Promise<number> - total number of columns in the table, taking merges into account
getId()
Returns the table ID.
getId(): Promise<string>;
Returns
Promise<string> - table ID
getRow(rowIndex)
Returns the row at the given position.
getRow(rowIndex: number): Promise<TableRow>;
Parameters
| Name | Type | Description |
|---|---|---|
rowIndex | number | row index (0-based) |
Returns
Promise<TableRow> - the row at that index
getRowCount()
Returns the number of rows in the table.
getRowCount(): Promise<number>;
Returns
Promise<number> - number of rows in the table
insertColumn(columnIndex, position)
Inserts a new column to the left or right of the reference column. - Access the cells of the new column by passing row and column indices to getCell().
insertColumn(columnIndex: number, position?: InsertAt): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
columnIndex | number | reference column index (0-based) |
position (optional) | InsertAt | insert position "before" (left of the reference column) | "after" (right of the reference column) (default: InsertAt.AFTER) |
Returns
Promise<void>
insertRow(rowIndex, position)
Inserts a new row before or after the reference row.
insertRow(rowIndex: number, position?: InsertAt): Promise<TableRow>;
Parameters
| Name | Type | Description |
|---|---|---|
rowIndex | number | reference row index (0-based) |
position (optional) | InsertAt | insert position "before" (above the reference row) | "after" (below the reference row) (default: InsertAt.AFTER) |
Returns
Promise<TableRow> - the newly created row
mergeCells(range)
Merges a cell range.
mergeCells(range: CellRange): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
range | CellRange | target cell range (anchor + count; at least one of rowSpan/colSpan must be 2 or more) |
Returns
Promise<void>
setAlignment(align)
Sets the horizontal position of the table within the page. - Set the horizontal alignment of cell content with setParagraphFormat() on the cell paragraph, and vertical alignment with setCellVerticalAlignment().
setAlignment(align: TableAlign): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
align | TableAlign | horizontal position "left" | "center" | "right" |
Returns
Promise<void>
setCellBackgroundColor(range, color)
Sets the background color of a cell range.
setCellBackgroundColor(range: CellRange, color: string | null): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
range | CellRange | target cell range (anchor + count) |
color | string | null | background color (hex "#RRGGBB"; null or "" removes it) |
Returns
Promise<void>
setCellBorder(range, border)
Sets the borders of a cell range.
setCellBorder(range: CellRange, border: Border): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
range | CellRange | target cell range (anchor + count) |
border | Border | border value (shared by paragraph/cell/page - see the Border typedef of WordRange.setParagraphBorder for field definitions) |
Returns
Promise<void>
setCellPadding(range, padding)
Sets the inner padding of the given cell range.
setCellPadding(range: CellRange, padding: Padding): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
range | CellRange | target cell range (anchor + count) |
padding | Padding | padding on 4 sides (pt; only the specified sides change) |
Returns
Promise<void>
setCellVerticalAlignment(range, align)
Sets the vertical alignment of a cell range.
setCellVerticalAlignment(range: CellRange, align: CellVerticalAlign): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
range | CellRange | target cell range (anchor + count) |
align | CellVerticalAlign | vertical alignment "top" | "center" | "bottom" |
Returns
Promise<void>
setColumnWidths(widths)
Sets the widths of all columns in the table.
The array length must equal the total number of columns. Columns with null keep their current width.
Values smaller than the minimum width are raised to the minimum.
setColumnWidths(widths: (number | null)[]): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
widths | (number | null)[] | array of column widths (pt). A null slot keeps the current value |
Returns
Promise<void>
setRowHeight(height, range)
Sets the target rows to the same given height.
setRowHeight(height: number, range?: CellRange): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
height | number | row height (pt, positive) |
range (optional) | CellRange | target row range. Only the row span (row/rowSpan) is used (default: whole table) |
Returns
Promise<void>
setRowHeights(heights)
Sets the row heights of the table row by row. - The array length must equal the number of rows. Rows with null keep their current height.
setRowHeights(heights: (number | null)[]): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
heights | (number | null)[] | array of row heights (pt). A null slot keeps the current value |
Returns
Promise<void>
setValues(values)
Replaces the content of multiple cells with text from a 2D array.
Puts values[r][c] into row r, column c. Cells not covered by the array and cells whose value is null or undefined are left unchanged.
Throws if the array exceeds the table size.
setValues(values: string[][]): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
values | string[][] | array of values per row (rows may have different column lengths) |
Returns
Promise<void>
unmergeCells(range)
Splits the merged cells within the given range.
unmergeCells(range: CellRange): Promise<void>;
Parameters
| Name | Type | Description |
|---|---|---|
range | CellRange | target cell range (omit the counts for a single cell) |
Returns
Promise<void>