Word.Table class
Represents a table in a Word document.
- Extends
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/table-cell-access.yaml
await Word.run(async (context) => {
// Use a two-dimensional array to hold the initial table values.
const data = [
["Tokyo", "Beijing", "Seattle"],
["Apple", "Orange", "Pineapple"]
];
const table: Word.Table = context.document.body.insertTable(2, 3, "Start", data);
table.styleBuiltIn = Word.BuiltInStyleName.gridTable5Dark_Accent2;
table.styleFirstColumn = false;
await context.sync();
});
Properties
alignment | Specifies the alignment of the table against the page column. The value can be 'Left', 'Centered', or 'Right'. |
context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
font | Gets the font. Use this to get and set font name, size, color, and other properties. |
header |
Specifies the number of header rows. |
horizontal |
Specifies the horizontal alignment of every cell in the table. The value can be 'Left', 'Centered', 'Right', or 'Justified'. |
is |
Indicates whether all of the table rows are uniform. |
nesting |
Gets the nesting level of the table. Top-level tables have level 1. |
parent |
Gets the parent body of the table. |
parent |
Gets the content control that contains the table. Throws an |
parent |
Gets the content control that contains the table. If there isn't a parent content control, then this method will return an object with its |
parent |
Gets the table that contains this table. Throws an |
parent |
Gets the table cell that contains this table. Throws an |
parent |
Gets the table cell that contains this table. If it isn't contained in a table cell, then this method will return an object with its |
parent |
Gets the table that contains this table. If it isn't contained in a table, then this method will return an object with its |
row |
Gets the number of rows in the table. |
rows | Gets all of the table rows. |
shading |
Specifies the shading color. Color is specified in "#RRGGBB" format or by using the color name. |
style | Specifies the style name for the table. Use this property for custom styles and localized style names. To use the built-in styles that are portable between locales, see the "styleBuiltIn" property. |
style |
Specifies whether the table has banded columns. |
style |
Specifies whether the table has banded rows. |
style |
Specifies the built-in style name for the table. Use this property for built-in styles that are portable between locales. To use custom styles or localized style names, see the "style" property. |
style |
Specifies whether the table has a first column with a special style. |
style |
Specifies whether the table has a last column with a special style. |
style |
Specifies whether the table has a total (last) row with a special style. |
tables | Gets the child tables nested one level deeper. |
values | Specifies the text values in the table, as a 2D JavaScript array. |
vertical |
Specifies the vertical alignment of every cell in the table. The value can be 'Top', 'Center', or 'Bottom'. |
width | Specifies the width of the table in points. |
Methods
add |
Adds columns to the start or end of the table, using the first or last existing column as a template. This is applicable to uniform tables. The string values, if specified, are set in the newly inserted rows. |
add |
Adds rows to the start or end of the table, using the first or last existing row as a template. The string values, if specified, are set in the newly inserted rows. |
auto |
Autofits the table columns to the width of the window. |
clear() | Clears the contents of the table. |
delete() | Deletes the entire table. |
delete |
Deletes specific columns. This is applicable to uniform tables. |
delete |
Deletes specific rows. |
distribute |
Distributes the column widths evenly. This is applicable to uniform tables. |
get |
Gets the border style for the specified border. |
get |
Gets the border style for the specified border. |
get |
Gets the table cell at a specified row and column. Throws an |
get |
Gets the table cell at a specified row and column. If the specified table cell doesn't exist, then this method will return an object with its |
get |
Gets cell padding in points. |
get |
Gets cell padding in points. |
get |
Gets the next table. Throws an |
get |
Gets the next table. If this table is the last one, then this method will return an object with its |
get |
Gets the paragraph after the table. Throws an |
get |
Gets the paragraph after the table. If there isn't a paragraph after the table, then this method will return an object with its |
get |
Gets the paragraph before the table. Throws an |
get |
Gets the paragraph before the table. If there isn't a paragraph before the table, then this method will return an object with its |
get |
Gets the range that contains this table, or the range at the start or end of the table. |
insert |
Inserts a content control on the table. |
insert |
Inserts a paragraph at the specified location. |
insert |
Inserts a table with the specified number of rows and columns. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
search(search |
Performs a search with the specified SearchOptions on the scope of the table object. The search results are a collection of range objects. |
select(selection |
Selects the table, or the position at the start or end of the table, and navigates the Word UI to it. |
select(selection |
Selects the table, or the position at the start or end of the table, and navigates the Word UI to it. |
set(properties, options) | Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type. |
set(properties) | Sets multiple properties on the object at the same time, based on an existing loaded object. |
set |
Sets cell padding in points. |
set |
Sets cell padding in points. |
toJSON() | Overrides the JavaScript |
track() | Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across |
untrack() | Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call |
Property Details
alignment
Specifies the alignment of the table against the page column. The value can be 'Left', 'Centered', or 'Right'.
alignment: Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified";
Property Value
Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml
// Gets alignment details about the first table in the document.
await Word.run(async (context) => {
const firstTable: Word.Table = context.document.body.tables.getFirst();
firstTable.load(["alignment", "horizontalAlignment", "verticalAlignment"]);
await context.sync();
console.log(`Details about the alignment of the first table:`, `- Alignment of the table within the containing page column: ${firstTable.alignment}`, `- Horizontal alignment of every cell in the table: ${firstTable.horizontalAlignment}`, `- Vertical alignment of every cell in the table: ${firstTable.verticalAlignment}`);
});
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
font
Gets the font. Use this to get and set font name, size, color, and other properties.
readonly font: Word.Font;
Property Value
Remarks
headerRowCount
Specifies the number of header rows.
headerRowCount: number;
Property Value
number
Remarks
horizontalAlignment
Specifies the horizontal alignment of every cell in the table. The value can be 'Left', 'Centered', 'Right', or 'Justified'.
horizontalAlignment: Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified";
Property Value
Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml
// Gets alignment details about the first table in the document.
await Word.run(async (context) => {
const firstTable: Word.Table = context.document.body.tables.getFirst();
firstTable.load(["alignment", "horizontalAlignment", "verticalAlignment"]);
await context.sync();
console.log(`Details about the alignment of the first table:`, `- Alignment of the table within the containing page column: ${firstTable.alignment}`, `- Horizontal alignment of every cell in the table: ${firstTable.horizontalAlignment}`, `- Vertical alignment of every cell in the table: ${firstTable.verticalAlignment}`);
});
isUniform
Indicates whether all of the table rows are uniform.
readonly isUniform: boolean;
Property Value
boolean
Remarks
nestingLevel
Gets the nesting level of the table. Top-level tables have level 1.
readonly nestingLevel: number;
Property Value
number
Remarks
parentBody
Gets the parent body of the table.
readonly parentBody: Word.Body;
Property Value
Remarks
parentContentControl
Gets the content control that contains the table. Throws an ItemNotFound
error if there isn't a parent content control.
readonly parentContentControl: Word.ContentControl;
Property Value
Remarks
parentContentControlOrNullObject
Gets the content control that contains the table. If there isn't a parent content control, then this method will return an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
readonly parentContentControlOrNullObject: Word.ContentControl;
Property Value
Remarks
parentTable
Gets the table that contains this table. Throws an ItemNotFound
error if it isn't contained in a table.
readonly parentTable: Word.Table;
Property Value
Remarks
parentTableCell
Gets the table cell that contains this table. Throws an ItemNotFound
error if it isn't contained in a table cell.
readonly parentTableCell: Word.TableCell;
Property Value
Remarks
parentTableCellOrNullObject
Gets the table cell that contains this table. If it isn't contained in a table cell, then this method will return an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
readonly parentTableCellOrNullObject: Word.TableCell;
Property Value
Remarks
parentTableOrNullObject
Gets the table that contains this table. If it isn't contained in a table, then this method will return an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
readonly parentTableOrNullObject: Word.Table;
Property Value
Remarks
rowCount
Gets the number of rows in the table.
readonly rowCount: number;
Property Value
number
Remarks
rows
Gets all of the table rows.
readonly rows: Word.TableRowCollection;
Property Value
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml
// Gets content alignment details about the first row of the first table in the document.
await Word.run(async (context) => {
const firstTable: Word.Table = context.document.body.tables.getFirst();
const firstTableRow: Word.TableRow = firstTable.rows.getFirst();
firstTableRow.load(["horizontalAlignment", "verticalAlignment"]);
await context.sync();
console.log(`Details about the alignment of the first table's first row:`, `- Horizontal alignment of every cell in the row: ${firstTableRow.horizontalAlignment}`, `- Vertical alignment of every cell in the row: ${firstTableRow.verticalAlignment}`);
});
shadingColor
Specifies the shading color. Color is specified in "#RRGGBB" format or by using the color name.
shadingColor: string;
Property Value
string
Remarks
style
Specifies the style name for the table. Use this property for custom styles and localized style names. To use the built-in styles that are portable between locales, see the "styleBuiltIn" property.
style: string;
Property Value
string
Remarks
styleBandedColumns
Specifies whether the table has banded columns.
styleBandedColumns: boolean;
Property Value
boolean
Remarks
styleBandedRows
Specifies whether the table has banded rows.
styleBandedRows: boolean;
Property Value
boolean
Remarks
styleBuiltIn
Specifies the built-in style name for the table. Use this property for built-in styles that are portable between locales. To use custom styles or localized style names, see the "style" property.
styleBuiltIn: Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6";
Property Value
Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6"
Remarks
styleFirstColumn
Specifies whether the table has a first column with a special style.
styleFirstColumn: boolean;
Property Value
boolean
Remarks
styleLastColumn
Specifies whether the table has a last column with a special style.
styleLastColumn: boolean;
Property Value
boolean
Remarks
styleTotalRow
Specifies whether the table has a total (last) row with a special style.
styleTotalRow: boolean;
Property Value
boolean
Remarks
tables
Gets the child tables nested one level deeper.
readonly tables: Word.TableCollection;
Property Value
Remarks
values
Specifies the text values in the table, as a 2D JavaScript array.
values: string[][];
Property Value
string[][]
Remarks
verticalAlignment
Specifies the vertical alignment of every cell in the table. The value can be 'Top', 'Center', or 'Bottom'.
verticalAlignment: Word.VerticalAlignment | "Mixed" | "Top" | "Center" | "Bottom";
Property Value
Word.VerticalAlignment | "Mixed" | "Top" | "Center" | "Bottom"
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml
// Gets alignment details about the first table in the document.
await Word.run(async (context) => {
const firstTable: Word.Table = context.document.body.tables.getFirst();
firstTable.load(["alignment", "horizontalAlignment", "verticalAlignment"]);
await context.sync();
console.log(`Details about the alignment of the first table:`, `- Alignment of the table within the containing page column: ${firstTable.alignment}`, `- Horizontal alignment of every cell in the table: ${firstTable.horizontalAlignment}`, `- Vertical alignment of every cell in the table: ${firstTable.verticalAlignment}`);
});
width
Specifies the width of the table in points.
width: number;
Property Value
number
Remarks
Method Details
addColumns(insertLocation, columnCount, values)
Adds columns to the start or end of the table, using the first or last existing column as a template. This is applicable to uniform tables. The string values, if specified, are set in the newly inserted rows.
addColumns(insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End", columnCount: number, values?: string[][]): void;
Parameters
Required. It must be 'Start' or 'End', corresponding to the appropriate side of the table.
- columnCount
-
number
Required. Number of columns to add.
- values
-
string[][]
Optional 2D array. Cells are filled if the corresponding strings are specified in the array.
Returns
void
Remarks
addRows(insertLocation, rowCount, values)
Adds rows to the start or end of the table, using the first or last existing row as a template. The string values, if specified, are set in the newly inserted rows.
addRows(insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End", rowCount: number, values?: string[][]): Word.TableRowCollection;
Parameters
- rowCount
-
number
Required. Number of rows to add.
- values
-
string[][]
Optional 2D array. Cells are filled if the corresponding strings are specified in the array.
Returns
Remarks
autoFitWindow()
Autofits the table columns to the width of the window.
autoFitWindow(): void;
Returns
void
Remarks
clear()
delete()
deleteColumns(columnIndex, columnCount)
Deletes specific columns. This is applicable to uniform tables.
deleteColumns(columnIndex: number, columnCount?: number): void;
Parameters
- columnIndex
-
number
Required. The first column to delete.
- columnCount
-
number
Optional. The number of columns to delete. Default 1.
Returns
void
Remarks
deleteRows(rowIndex, rowCount)
Deletes specific rows.
deleteRows(rowIndex: number, rowCount?: number): void;
Parameters
- rowIndex
-
number
Required. The first row to delete.
- rowCount
-
number
Optional. The number of rows to delete. Default 1.
Returns
void
Remarks
distributeColumns()
Distributes the column widths evenly. This is applicable to uniform tables.
distributeColumns(): void;
Returns
void
Remarks
getBorder(borderLocation)
Gets the border style for the specified border.
getBorder(borderLocation: Word.BorderLocation): Word.TableBorder;
Parameters
- borderLocation
- Word.BorderLocation
Required. The border location.
Returns
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml
// Gets border details about the first table in the document.
await Word.run(async (context) => {
const firstTable: Word.Table = context.document.body.tables.getFirst();
const borderLocation = Word.BorderLocation.top;
const border: Word.TableBorder = firstTable.getBorder(borderLocation);
border.load(["type", "color", "width"]);
await context.sync();
console.log(`Details about the ${borderLocation} border of the first table:`, `- Color: ${border.color}`, `- Type: ${border.type}`, `- Width: ${border.width} points`);
});
getBorder(borderLocationString)
Gets the border style for the specified border.
getBorder(borderLocationString: "Top" | "Left" | "Bottom" | "Right" | "InsideHorizontal" | "InsideVertical" | "Inside" | "Outside" | "All"): Word.TableBorder;
Parameters
- borderLocationString
-
"Top" | "Left" | "Bottom" | "Right" | "InsideHorizontal" | "InsideVertical" | "Inside" | "Outside" | "All"
Required. The border location.
Returns
Remarks
getCell(rowIndex, cellIndex)
Gets the table cell at a specified row and column. Throws an ItemNotFound
error if the specified table cell doesn't exist.
getCell(rowIndex: number, cellIndex: number): Word.TableCell;
Parameters
- rowIndex
-
number
Required. The index of the row.
- cellIndex
-
number
Required. The index of the cell in the row.
Returns
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/table-cell-access.yaml
// Gets the content of the first cell in the first table.
await Word.run(async (context) => {
const firstCell: Word.Body = context.document.body.tables.getFirst().getCell(0, 0).body;
firstCell.load("text");
await context.sync();
console.log("First cell's text is: " + firstCell.text);
});
getCellOrNullObject(rowIndex, cellIndex)
Gets the table cell at a specified row and column. If the specified table cell doesn't exist, then this method will return an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
getCellOrNullObject(rowIndex: number, cellIndex: number): Word.TableCell;
Parameters
- rowIndex
-
number
Required. The index of the row.
- cellIndex
-
number
Required. The index of the cell in the row.
Returns
Remarks
getCellPadding(cellPaddingLocation)
Gets cell padding in points.
getCellPadding(cellPaddingLocation: Word.CellPaddingLocation): OfficeExtension.ClientResult<number>;
Parameters
- cellPaddingLocation
- Word.CellPaddingLocation
Required. The cell padding location must be 'Top', 'Left', 'Bottom', or 'Right'.
Returns
OfficeExtension.ClientResult<number>
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml
// Gets cell padding details about the first table in the document.
await Word.run(async (context) => {
const firstTable: Word.Table = context.document.body.tables.getFirst();
const cellPaddingLocation = Word.CellPaddingLocation.right;
const cellPadding = firstTable.getCellPadding(cellPaddingLocation);
await context.sync();
console.log(
`Cell padding details about the ${cellPaddingLocation} border of the first table: ${cellPadding.value} points`
);
});
getCellPadding(cellPaddingLocationString)
Gets cell padding in points.
getCellPadding(cellPaddingLocationString: "Top" | "Left" | "Bottom" | "Right"): OfficeExtension.ClientResult<number>;
Parameters
- cellPaddingLocationString
-
"Top" | "Left" | "Bottom" | "Right"
Required. The cell padding location must be 'Top', 'Left', 'Bottom', or 'Right'.
Returns
OfficeExtension.ClientResult<number>
Remarks
getNext()
Gets the next table. Throws an ItemNotFound
error if this table is the last one.
getNext(): Word.Table;
Returns
Remarks
getNextOrNullObject()
Gets the next table. If this table is the last one, then this method will return an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
getNextOrNullObject(): Word.Table;
Returns
Remarks
getParagraphAfter()
Gets the paragraph after the table. Throws an ItemNotFound
error if there isn't a paragraph after the table.
getParagraphAfter(): Word.Paragraph;
Returns
Remarks
getParagraphAfterOrNullObject()
Gets the paragraph after the table. If there isn't a paragraph after the table, then this method will return an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
getParagraphAfterOrNullObject(): Word.Paragraph;
Returns
Remarks
getParagraphBefore()
Gets the paragraph before the table. Throws an ItemNotFound
error if there isn't a paragraph before the table.
getParagraphBefore(): Word.Paragraph;
Returns
Remarks
getParagraphBeforeOrNullObject()
Gets the paragraph before the table. If there isn't a paragraph before the table, then this method will return an object with its isNullObject
property set to true
. For further information, see *OrNullObject methods and properties.
getParagraphBeforeOrNullObject(): Word.Paragraph;
Returns
Remarks
getRange(rangeLocation)
Gets the range that contains this table, or the range at the start or end of the table.
getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | Word.RangeLocation.after | "Whole" | "Start" | "End" | "After"): Word.Range;
Parameters
Optional. The range location must be 'Whole', 'Start', 'End', or 'After'.
Returns
Remarks
insertContentControl()
Inserts a content control on the table.
insertContentControl(): Word.ContentControl;
Returns
Remarks
insertParagraph(paragraphText, insertLocation)
Inserts a paragraph at the specified location.
insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Paragraph;
Parameters
- paragraphText
-
string
Required. The paragraph text to be inserted.
Returns
Remarks
insertTable(rowCount, columnCount, insertLocation, values)
Inserts a table with the specified number of rows and columns.
insertTable(rowCount: number, columnCount: number, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After", values?: string[][]): Word.Table;
Parameters
- rowCount
-
number
Required. The number of rows in the table.
- columnCount
-
number
Required. The number of columns in the table.
- values
-
string[][]
Optional 2D array. Cells are filled if the corresponding strings are specified in the array.
Returns
Remarks
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(options?: Word.Interfaces.TableLoadOptions): Word.Table;
Parameters
- options
- Word.Interfaces.TableLoadOptions
Provides options for which properties of the object to load.
Returns
load(propertyNames)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNames?: string | string[]): Word.Table;
Parameters
- propertyNames
-
string | string[]
A comma-delimited string or an array of strings that specify the properties to load.
Returns
load(propertyNamesAndPaths)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): Word.Table;
Parameters
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select
is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand
is a comma-delimited string that specifies the navigation properties to load.
Returns
search(searchText, searchOptions)
Performs a search with the specified SearchOptions on the scope of the table object. The search results are a collection of range objects.
search(searchText: string, searchOptions?: Word.SearchOptions | {
ignorePunct?: boolean;
ignoreSpace?: boolean;
matchCase?: boolean;
matchPrefix?: boolean;
matchSuffix?: boolean;
matchWholeWord?: boolean;
matchWildcards?: boolean;
}): Word.RangeCollection;
Parameters
- searchText
-
string
Required. The search text.
- searchOptions
-
Word.SearchOptions | { ignorePunct?: boolean; ignoreSpace?: boolean; matchCase?: boolean; matchPrefix?: boolean; matchSuffix?: boolean; matchWholeWord?: boolean; matchWildcards?: boolean; }
Optional. Options for the search.
Returns
Remarks
select(selectionMode)
Selects the table, or the position at the start or end of the table, and navigates the Word UI to it.
select(selectionMode?: Word.SelectionMode): void;
Parameters
- selectionMode
- Word.SelectionMode
Optional. The selection mode must be 'Select', 'Start', or 'End'. 'Select' is the default.
Returns
void
Remarks
select(selectionModeString)
Selects the table, or the position at the start or end of the table, and navigates the Word UI to it.
select(selectionModeString?: "Select" | "Start" | "End"): void;
Parameters
- selectionModeString
-
"Select" | "Start" | "End"
Optional. The selection mode must be 'Select', 'Start', or 'End'. 'Select' is the default.
Returns
void
Remarks
set(properties, options)
Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.
set(properties: Interfaces.TableUpdateData, options?: OfficeExtension.UpdateOptions): void;
Parameters
- properties
- Word.Interfaces.TableUpdateData
A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.
- options
- OfficeExtension.UpdateOptions
Provides an option to suppress errors if the properties object tries to set any read-only properties.
Returns
void
set(properties)
Sets multiple properties on the object at the same time, based on an existing loaded object.
set(properties: Word.Table): void;
Parameters
- properties
- Word.Table
Returns
void
setCellPadding(cellPaddingLocation, cellPadding)
Sets cell padding in points.
setCellPadding(cellPaddingLocation: Word.CellPaddingLocation, cellPadding: number): void;
Parameters
- cellPaddingLocation
- Word.CellPaddingLocation
Required. The cell padding location must be 'Top', 'Left', 'Bottom', or 'Right'.
- cellPadding
-
number
Required. The cell padding.
Returns
void
Remarks
setCellPadding(cellPaddingLocationString, cellPadding)
Sets cell padding in points.
setCellPadding(cellPaddingLocationString: "Top" | "Left" | "Bottom" | "Right", cellPadding: number): void;
Parameters
- cellPaddingLocationString
-
"Top" | "Left" | "Bottom" | "Right"
Required. The cell padding location must be 'Top', 'Left', 'Bottom', or 'Right'.
- cellPadding
-
number
Required. The cell padding.
Returns
void
Remarks
toJSON()
Overrides the JavaScript toJSON()
method in order to provide more useful output when an API object is passed to JSON.stringify()
. (JSON.stringify
, in turn, calls the toJSON
method of the object that's passed to it.) Whereas the original Word.Table
object is an API object, the toJSON
method returns a plain JavaScript object (typed as Word.Interfaces.TableData
) that contains shallow copies of any loaded child properties from the original object.
toJSON(): Word.Interfaces.TableData;
Returns
track()
Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync
calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created. If this object is part of a collection, you should also track the parent collection.
track(): Word.Table;
Returns
untrack()
Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You'll need to call context.sync()
before the memory release takes effect.
untrack(): Word.Table;
Returns
Office Add-ins