Edit

Share via


Word.TableCellCollection class

Contains the collection of the document's TableCell objects.

Extends

Remarks

[ API set: WordApi 1.3 ]

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 cell 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();
  const firstCell: Word.TableCell = firstTableRow.cells.getFirst();
  firstCell.load(["horizontalAlignment", "verticalAlignment"]);
  await context.sync();

  console.log(`Details about the alignment of the first table's first cell:`, `- Horizontal alignment of the cell's content: ${firstCell.horizontalAlignment}`, `- Vertical alignment of the cell's content: ${firstCell.verticalAlignment}`);
});

Properties

context

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

items

Gets the loaded child items in this collection.

Methods

autoFit()

Changes the width of a table column to accommodate the width of the text without changing the way text wraps in the cells.

delete(shiftCells)

Deletes the table cells and optionally controls how the remaining cells are shifted.

delete(shiftCells)

Deletes the table cells and optionally controls how the remaining cells are shifted.

distributeHeight()

Adjusts the height of the specified cells so that they are equal.

distributeWidth()

Adjusts the width of the specified cells so that they are equal.

getFirst()

Gets the first table cell in this collection. Throws an ItemNotFound error if this collection is empty.

getFirstOrNullObject()

Gets the first table cell in this collection. If this collection is empty, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

load(options)

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.

merge()

Merges the specified cells into a single cell.

setHeight(rowHeight, heightRule)

Sets the height of the cells in a table.

setHeight(rowHeight, heightRule)

Sets the height of the cells in a table.

setWidth(columnWidth, rulerStyle)

Sets the width of the cells in a table.

setWidth(columnWidth, rulerStyle)

Sets the width of the cells in a table.

split(options)

Splits this range of table cells.

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.TableCellCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TableCellCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

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.

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.

Property Details

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

items

Gets the loaded child items in this collection.

readonly items: Word.TableCell[];

Property Value

Method Details

autoFit()

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.

Changes the width of a table column to accommodate the width of the text without changing the way text wraps in the cells.

autoFit(): void;

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

delete(shiftCells)

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.

Deletes the table cells and optionally controls how the remaining cells are shifted.

delete(shiftCells?: Word.DeleteCells): void;

Parameters

shiftCells
Word.DeleteCells

Optional. Specifies how the remaining cells are shifted after the deletion. The default is shiftLeft.

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

delete(shiftCells)

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.

Deletes the table cells and optionally controls how the remaining cells are shifted.

delete(shiftCells?: "ShiftLeft" | "ShiftUp" | "EntireRow" | "EntireColumn"): void;

Parameters

shiftCells

"ShiftLeft" | "ShiftUp" | "EntireRow" | "EntireColumn"

Optional. Specifies how the remaining cells are shifted after the deletion. The default is shiftLeft.

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

distributeHeight()

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.

Adjusts the height of the specified cells so that they are equal.

distributeHeight(): void;

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

distributeWidth()

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.

Adjusts the width of the specified cells so that they are equal.

distributeWidth(): void;

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

getFirst()

Gets the first table cell in this collection. Throws an ItemNotFound error if this collection is empty.

getFirst(): Word.TableCell;

Returns

Remarks

[ API set: WordApi 1.3 ]

getFirstOrNullObject()

Gets the first table cell in this collection. If this collection is empty, then this method will return an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

getFirstOrNullObject(): Word.TableCell;

Returns

Remarks

[ API set: WordApi 1.3 ]

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.TableCellCollectionLoadOptions & Word.Interfaces.CollectionLoadOptions): Word.TableCellCollection;

Parameters

options

Word.Interfaces.TableCellCollectionLoadOptions & Word.Interfaces.CollectionLoadOptions

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

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?: OfficeExtension.LoadOption): Word.TableCellCollection;

Parameters

propertyNamesAndPaths
OfficeExtension.LoadOption

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

merge()

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.

Merges the specified cells into a single cell.

merge(): void;

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

setHeight(rowHeight, heightRule)

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.

Sets the height of the cells in a table.

setHeight(rowHeight: number, heightRule: Word.RowHeightRule): void;

Parameters

rowHeight

number

The height of the row to set, in points.

heightRule
Word.RowHeightRule

The rule for determining the height of the specified rows.

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

setHeight(rowHeight, heightRule)

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.

Sets the height of the cells in a table.

setHeight(rowHeight: number, heightRule: "Auto" | "AtLeast" | "Exactly"): void;

Parameters

rowHeight

number

The height of the row to set, in points.

heightRule

"Auto" | "AtLeast" | "Exactly"

The rule for determining the height of the specified rows.

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

setWidth(columnWidth, rulerStyle)

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.

Sets the width of the cells in a table.

setWidth(columnWidth: number, rulerStyle: Word.RulerStyle): void;

Parameters

columnWidth

number

The width of the row to set, in points.

rulerStyle
Word.RulerStyle

The ruler style to apply.

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

setWidth(columnWidth, rulerStyle)

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.

Sets the width of the cells in a table.

setWidth(columnWidth: number, rulerStyle: "None" | "Proportional" | "FirstColumn" | "SameWidth"): void;

Parameters

columnWidth

number

The width of the row to set, in points.

rulerStyle

"None" | "Proportional" | "FirstColumn" | "SameWidth"

The ruler style to apply.

Returns

void

Remarks

[ API set: WordApi BETA (PREVIEW ONLY) ]

split(options)

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 this range of table cells.

split(options?: Word.TableCellCollectionSplitOptions): void;

Parameters

options
Word.TableCellCollectionSplitOptions

TableCellCollectionSplitOptions.

Returns

void

Remarks

[ 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's passed to it.) Whereas the original Word.TableCellCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TableCellCollectionData) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

toJSON(): Word.Interfaces.TableCellCollectionData;

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

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

Returns