Word.TableCellCollection class
Contains the collection of the document's TableCell objects.
- Extends
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 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
auto |
Changes the width of a table column to accommodate the width of the text without changing the way text wraps in the cells. |
delete(shift |
Deletes the table cells and optionally controls how the remaining cells are shifted. |
delete(shift |
Deletes the table cells and optionally controls how the remaining cells are shifted. |
distribute |
Adjusts the height of the specified cells so that they are equal. |
distribute |
Adjusts the width of the specified cells so that they are equal. |
get |
Gets the first table cell in this collection. Throws an |
get |
Gets the first table cell in this collection. If this collection is empty, then this method will return an object with its |
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 |
merge() | Merges the specified cells into a single cell. |
set |
Sets the height of the cells in a table. |
set |
Sets the height of the cells in a table. |
set |
Sets the width of the cells in a table. |
set |
Sets the width of the cells in a table. |
split(options) | Splits this range of table cells. |
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
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
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
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
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
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
getFirst()
Gets the first table cell in this collection. Throws an ItemNotFound
error if this collection is empty.
getFirst(): Word.TableCell;
Returns
Remarks
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
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
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
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
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
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
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
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
TableCellCollectionSplitOptions.
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.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;