Word.TableCell class

Represents a table cell in a Word document.

[ API set: WordApi 1.3 ]

Extends
OfficeExtension.ClientObject

Properties

body

Gets the body object of the cell. Read-only.

[ API set: WordApi 1.3 ]

cellIndex

Gets the index of the cell in its row. Read-only.

[ API set: WordApi 1.3 ]

columnWidth

Gets and sets the width of the cell's column in points. This is applicable to uniform tables.

[ API set: WordApi 1.3 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

horizontalAlignment

Gets and sets the horizontal alignment of the cell. The value can be 'Left', 'Centered', 'Right', or 'Justified'.

[ API set: WordApi 1.3 ]

parentRow

Gets the parent row of the cell. Read-only.

[ API set: WordApi 1.3 ]

parentTable

Gets the parent table of the cell. Read-only.

[ API set: WordApi 1.3 ]

rowIndex

Gets the index of the cell's row in the table. Read-only.

[ API set: WordApi 1.3 ]

shadingColor

Gets or sets the shading color of the cell. Color is specified in "#RRGGBB" format or by using the color name.

[ API set: WordApi 1.3 ]

value

Gets and sets the text of the cell.

[ API set: WordApi 1.3 ]

verticalAlignment

Gets and sets the vertical alignment of the cell. The value can be 'Top', 'Center', or 'Bottom'.

[ API set: WordApi 1.3 ]

width

Gets the width of the cell in points. Read-only.

[ API set: WordApi 1.3 ]

Methods

deleteColumn()

Deletes the column containing this cell. This is applicable to uniform tables.

[ API set: WordApi 1.3 ]

deleteRow()

Deletes the row containing this cell.

[ API set: WordApi 1.3 ]

getBorder(borderLocation)

Gets the border style for the specified border.

[ API set: WordApi 1.3 ]

getBorder(borderLocationString)

Gets the border style for the specified border.

[ API set: WordApi 1.3 ]

getCellPadding(cellPaddingLocation)

Gets cell padding in points.

[ API set: WordApi 1.3 ]

getCellPadding(cellPaddingLocationString)

Gets cell padding in points.

[ API set: WordApi 1.3 ]

getNext()

Gets the next cell. Throws an error if this cell is the last one.

[ API set: WordApi 1.3 ]

getNextOrNullObject()

Gets the next cell. Returns a null object if this cell is the last one.

[ API set: WordApi 1.3 ]

insertColumns(insertLocation, columnCount, values)

Adds columns to the left or right of the cell, using the cell's column as a template. This is applicable to uniform tables. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

insertColumns(insertLocationString, columnCount, values)

Adds columns to the left or right of the cell, using the cell's column as a template. This is applicable to uniform tables. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

insertRows(insertLocation, rowCount, values)

Inserts rows above or below the cell, using the cell's row as a template. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

insertRows(insertLocationString, rowCount, values)

Inserts rows above or below the cell, using the cell's row as a template. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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.

setCellPadding(cellPaddingLocation, cellPadding)

Sets cell padding in points.

[ API set: WordApi 1.3 ]

setCellPadding(cellPaddingLocationString, cellPadding)

Sets cell padding in points.

[ API set: WordApi 1.3 ]

split(rowCount, columnCount)

Splits the cell into the specified number of rows and columns.

[ API set: WordApi BETA (PREVIEW ONLY) ]

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 is passed to it.) Whereas the original Word.TableCell object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TableCellData) that contains shallow copies of any loaded child properties from the original object.

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 are 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 needed to have added the object to the tracked object collection when the object was first created.

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 will need to call "context.sync()" before the memory release takes effect.

Property Details

body

Gets the body object of the cell. Read-only.

[ API set: WordApi 1.3 ]

readonly body: Word.Body;

Property Value

cellIndex

Gets the index of the cell in its row. Read-only.

[ API set: WordApi 1.3 ]

readonly cellIndex: number;

Property Value

number

columnWidth

Gets and sets the width of the cell's column in points. This is applicable to uniform tables.

[ API set: WordApi 1.3 ]

columnWidth: number;

Property Value

number

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

horizontalAlignment

Gets and sets the horizontal alignment of the cell. The value can be 'Left', 'Centered', 'Right', or 'Justified'.

[ API set: WordApi 1.3 ]

horizontalAlignment: Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified";

Property Value

Word.Alignment | "Mixed" | "Unknown" | "Left" | "Centered" | "Right" | "Justified"

parentRow

Gets the parent row of the cell. Read-only.

[ API set: WordApi 1.3 ]

readonly parentRow: Word.TableRow;

Property Value

parentTable

Gets the parent table of the cell. Read-only.

[ API set: WordApi 1.3 ]

readonly parentTable: Word.Table;

Property Value

rowIndex

Gets the index of the cell's row in the table. Read-only.

[ API set: WordApi 1.3 ]

readonly rowIndex: number;

Property Value

number

shadingColor

Gets or sets the shading color of the cell. Color is specified in "#RRGGBB" format or by using the color name.

[ API set: WordApi 1.3 ]

shadingColor: string;

Property Value

string

value

Gets and sets the text of the cell.

[ API set: WordApi 1.3 ]

value: string;

Property Value

string

verticalAlignment

Gets and sets the vertical alignment of the cell. The value can be 'Top', 'Center', or 'Bottom'.

[ API set: WordApi 1.3 ]

verticalAlignment: Word.VerticalAlignment | "Mixed" | "Top" | "Center" | "Bottom";

Property Value

Word.VerticalAlignment | "Mixed" | "Top" | "Center" | "Bottom"

width

Gets the width of the cell in points. Read-only.

[ API set: WordApi 1.3 ]

readonly width: number;

Property Value

number

Method Details

deleteColumn()

Deletes the column containing this cell. This is applicable to uniform tables.

[ API set: WordApi 1.3 ]

deleteColumn(): void;

Returns

void

deleteRow()

Deletes the row containing this cell.

[ API set: WordApi 1.3 ]

deleteRow(): void;

Returns

void

getBorder(borderLocation)

Gets the border style for the specified border.

[ API set: WordApi 1.3 ]

getBorder(borderLocation: Word.BorderLocation): Word.TableBorder;

Parameters

borderLocation
Word.BorderLocation

Required. The border location.

Returns

getBorder(borderLocationString)

Gets the border style for the specified border.

[ API set: WordApi 1.3 ]

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

getCellPadding(cellPaddingLocation)

Gets cell padding in points.

[ API set: WordApi 1.3 ]

getCellPadding(cellPaddingLocation: Word.CellPaddingLocation): OfficeExtension.ClientResult<number>;

Parameters

cellPaddingLocation
Word.CellPaddingLocation

Required. The cell padding location can be 'Top', 'Left', 'Bottom', or 'Right'.

Returns

OfficeExtension.ClientResult<number>

getCellPadding(cellPaddingLocationString)

Gets cell padding in points.

[ API set: WordApi 1.3 ]

getCellPadding(cellPaddingLocationString: "Top" | "Left" | "Bottom" | "Right"): OfficeExtension.ClientResult<number>;

Parameters

cellPaddingLocationString
"Top" | "Left" | "Bottom" | "Right"

Required. The cell padding location can be 'Top', 'Left', 'Bottom', or 'Right'.

Returns

OfficeExtension.ClientResult<number>

getNext()

Gets the next cell. Throws an error if this cell is the last one.

[ API set: WordApi 1.3 ]

getNext(): Word.TableCell;

Returns

getNextOrNullObject()

Gets the next cell. Returns a null object if this cell is the last one.

[ API set: WordApi 1.3 ]

getNextOrNullObject(): Word.TableCell;

Returns

insertColumns(insertLocation, columnCount, values)

Adds columns to the left or right of the cell, using the cell's column as a template. This is applicable to uniform tables. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

insertColumns(insertLocation: Word.InsertLocation, columnCount: number, values?: string[][]): void;

Parameters

insertLocation
Word.InsertLocation

Required. It can be 'Before' or 'After'.

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

insertColumns(insertLocationString, columnCount, values)

Adds columns to the left or right of the cell, using the cell's column as a template. This is applicable to uniform tables. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

insertColumns(insertLocationString: "Before" | "After" | "Start" | "End" | "Replace", columnCount: number, values?: string[][]): void;

Parameters

insertLocationString
"Before" | "After" | "Start" | "End" | "Replace"

Required. It can be 'Before' or 'After'.

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

insertRows(insertLocation, rowCount, values)

Inserts rows above or below the cell, using the cell's row as a template. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

insertRows(insertLocation: Word.InsertLocation, rowCount: number, values?: string[][]): Word.TableRowCollection;

Parameters

insertLocation
Word.InsertLocation

Required. It can be 'Before' or 'After'.

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

insertRows(insertLocationString, rowCount, values)

Inserts rows above or below the cell, using the cell's row as a template. The string values, if specified, are set in the newly inserted rows.

[ API set: WordApi 1.3 ]

insertRows(insertLocationString: "Before" | "After" | "Start" | "End" | "Replace", rowCount: number, values?: string[][]): Word.TableRowCollection;

Parameters

insertLocationString
"Before" | "After" | "Start" | "End" | "Replace"

Required. It can be 'Before' or 'After'.

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

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: Word.Interfaces.TableCellLoadOptions): Word.TableCell;

Parameters

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Word.TableCell - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Word.TableCell - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Word.TableCell - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. If option.top is specified, the result set will start after skipping the specified number of items.

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.TableCell;

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.TableCell;

Parameters

propertyNamesAndPaths
{ select?: string; expand?: string; }

Where 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

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.TableCellUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
Interfaces.TableCellUpdateData

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

Remarks

This method has the following additional signature:

set(properties: Word.TableCell): void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Word.TableCell): void;

Parameters

properties
Word.TableCell

Returns

void

setCellPadding(cellPaddingLocation, cellPadding)

Sets cell padding in points.

[ API set: WordApi 1.3 ]

setCellPadding(cellPaddingLocation: Word.CellPaddingLocation, cellPadding: number): void;

Parameters

cellPaddingLocation
Word.CellPaddingLocation

Required. The cell padding location can be 'Top', 'Left', 'Bottom', or 'Right'.

cellPadding
number

Required. The cell padding.

Returns

void

setCellPadding(cellPaddingLocationString, cellPadding)

Sets cell padding in points.

[ API set: WordApi 1.3 ]

setCellPadding(cellPaddingLocationString: "Top" | "Left" | "Bottom" | "Right", cellPadding: number): void;

Parameters

cellPaddingLocationString
"Top" | "Left" | "Bottom" | "Right"

Required. The cell padding location can be 'Top', 'Left', 'Bottom', or 'Right'.

cellPadding
number

Required. The cell padding.

Returns

void

split(rowCount, columnCount)

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Splits the cell into the specified number of rows and columns.

[ API set: WordApi BETA (PREVIEW ONLY) ]

split(rowCount: number, columnCount: number): void;

Parameters

rowCount
number

Required. The number of rows to split into. Must be a divisor of the number of underlying rows.

columnCount
number

Required. The number of columns to split into.

Returns

void

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 is passed to it.) Whereas the original Word.TableCell object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TableCellData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Word.Interfaces.TableCellData;

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 are 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 needed to have added the object to the tracked object collection when the object was first created.

track(): Word.TableCell;

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 will need to call "context.sync()" before the memory release takes effect.

untrack(): Word.TableCell;

Returns