Edit

Share via


Word.TableRowCollection class

Contains the collection of the document's Word.TableRow 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 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}`);
});

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

convertToText(options)

Converts rows in a table to text.

delete()

Deletes the table rows.

distributeHeight()

Adjusts the height of the rows so that they're equal.

getFirst()

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

getFirstOrNullObject()

Gets the first row 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.

select()

Selects the table rows.

setHeight(rowHeight, heightRule)

Sets the height of the cells in a table.

setHeight(rowHeight, heightRule)

Sets the height of the cells in a table.

setLeftIndent(leftIndent, rulerStyle)

Sets the left indent for the table row.

setLeftIndent(leftIndent, rulerStyle)

Sets the left indent for the table row.

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.TableRowCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.TableRowCollectionData) 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.TableRow[];

Property Value

Method Details

convertToText(options)

Converts rows in a table to text.

convertToText(options?: Word.TableConvertToTextOptions): Word.Range;

Parameters

options
Word.TableConvertToTextOptions

Optional. An object that specifies the options for converting the table rows to text.

Returns

A Range object that represents the converted text.

Remarks

[ API set: WordApiDesktop 1.4 ]

delete()

Deletes the table rows.

delete(): void;

Returns

void

Remarks

[ API set: WordApiDesktop 1.4 ]

distributeHeight()

Adjusts the height of the rows so that they're equal.

distributeHeight(): void;

Returns

void

Remarks

[ API set: WordApiDesktop 1.4 ]

getFirst()

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

getFirst(): Word.TableRow;

Returns

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 border 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();
  const borderLocation = Word.BorderLocation.bottom;
  const border: Word.TableBorder = firstTableRow.getBorder(borderLocation);
  border.load(["type", "color", "width"]);
  await context.sync();

  console.log(`Details about the ${borderLocation} border of the first table's first row:`, `- Color: ${border.color}`, `- Type: ${border.type}`, `- Width: ${border.width} points`);
});

getFirstOrNullObject()

Gets the first row 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.TableRow;

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

Parameters

options

Word.Interfaces.TableRowCollectionLoadOptions & 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.TableRowCollection;

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

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

select()

Selects the table rows.

select(): void;

Returns

void

Remarks

[ API set: WordApiDesktop 1.4 ]

setHeight(rowHeight, heightRule)

Sets the height of the cells in a table.

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

Parameters

rowHeight

number

The height of the row, in points.

heightRule
Word.RowHeightRule

The rule for determining the height of the specified rows.

Returns

void

Remarks

[ API set: WordApiDesktop 1.4 ]

setHeight(rowHeight, heightRule)

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, in points.

heightRule

"Auto" | "AtLeast" | "Exactly"

The rule for determining the height of the specified rows.

Returns

void

Remarks

[ API set: WordApiDesktop 1.4 ]

setLeftIndent(leftIndent, rulerStyle)

Sets the left indent for the table row.

setLeftIndent(leftIndent: number, rulerStyle: Word.RulerStyle): void;

Parameters

leftIndent

number

The distance (in points) between the current left edge of the specified rows and the desired left edge.

rulerStyle
Word.RulerStyle

The ruler style to apply.

Returns

void

Remarks

[ API set: WordApiDesktop 1.4 ]

setLeftIndent(leftIndent, rulerStyle)

Sets the left indent for the table row.

setLeftIndent(leftIndent: number, rulerStyle: "None" | "Proportional" | "FirstColumn" | "SameWidth"): void;

Parameters

leftIndent

number

The distance (in points) between the current left edge of the specified rows and the desired left edge.

rulerStyle

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

The ruler style to apply.

Returns

void

Remarks

[ API set: WordApiDesktop 1.4 ]

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

toJSON(): Word.Interfaces.TableRowCollectionData;

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

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

Returns