Word.TableRowCollection class

包含文档的 Word 集合。TableRow 对象。

扩展

注解

API 集:WordApi 1.3

使用方

示例

// 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}`,
  );
});

属性

context

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

items

获取此集合中已加载的子项。

方法

convertToText(options)

将表中的行转换为文本。

delete()

删除表行。

distributeHeight()

调整行的高度,使其相等。

getFirst()

获取此集合中的第一行。 如果此集合为空,则引发 ItemNotFound 错误。

getFirstOrNullObject()

获取此集合中的第一行。 如果此集合为空,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

select()

选择表行。

setHeight(rowHeight, heightRule)

设置表格中单元格的高度。

setHeight(rowHeight, heightRule)

设置表格中单元格的高度。

setLeftIndent(leftIndent, rulerStyle)

设置表行的左缩进。

setLeftIndent(leftIndent, rulerStyle)

设置表行的左缩进。

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Word.TableRowCollection 对象是 API 对象,但该 toJSON 方法返回一个纯 JavaScript 对象, (类型为 Word.Interfaces.TableRowCollectionData) ,其中包含一个“items”数组,其中包含从集合的 items 中加载的任何属性的浅层副本。

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 .sync 使用此对象,并且在“.run”批处理的顺序执行之外使用此对象,并且在设置属性或对对象调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪对象集合。 如果此对象是集合的一部分,您还应跟踪父集合。

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 context.sync()

属性详细信息

context

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

items

获取此集合中已加载的子项。

readonly items: Word.TableRow[];

属性值

方法详细信息

convertToText(options)

将表中的行转换为文本。

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

参数

options
Word.TableConvertToTextOptions

可选。 指定用于将表格行转换为文本的选项的对象。

返回

Range表示已转换文本的对象。

注解

API 集:WordApiDesktop 1.4

delete()

删除表行。

delete(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

distributeHeight()

调整行的高度,使其相等。

distributeHeight(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

getFirst()

获取此集合中的第一行。 如果此集合为空,则引发 ItemNotFound 错误。

getFirst(): Word.TableRow;

返回

注解

API 集:WordApi 1.3

示例

// 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()

获取此集合中的第一行。 如果此集合为空,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

getFirstOrNullObject(): Word.TableRow;

返回

注解

API 集:WordApi 1.3

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: Word.Interfaces.TableRowCollectionLoadOptions & Word.Interfaces.CollectionLoadOptions): Word.TableRowCollection;

参数

options

Word.Interfaces.TableRowCollectionLoadOptions & Word.Interfaces.CollectionLoadOptions

为要加载的对象属性提供选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): Word.TableRowCollection;

参数

propertyNames

string | string[]

指定要加载的属性的逗号分隔的字符串或字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Word.TableRowCollection;

参数

propertyNamesAndPaths
OfficeExtension.LoadOption

propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。

返回

select()

选择表行。

select(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

setHeight(rowHeight, heightRule)

设置表格中单元格的高度。

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

参数

rowHeight

number

行的高度,以磅为单位。

heightRule
Word.RowHeightRule

用于确定指定行的高度的规则。

返回

void

注解

API 集:WordApiDesktop 1.4

setHeight(rowHeight, heightRule)

设置表格中单元格的高度。

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

参数

rowHeight

number

行的高度,以磅为单位。

heightRule

"Auto" | "AtLeast" | "Exactly"

用于确定指定行的高度的规则。

返回

void

注解

API 集:WordApiDesktop 1.4

setLeftIndent(leftIndent, rulerStyle)

设置表行的左缩进。

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

参数

leftIndent

number

指定行的当前左边缘与所需左边缘之间的距离) (。

rulerStyle
Word.RulerStyle

要应用的标尺样式。

返回

void

注解

API 集:WordApiDesktop 1.4

setLeftIndent(leftIndent, rulerStyle)

设置表行的左缩进。

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

参数

leftIndent

number

指定行的当前左边缘与所需左边缘之间的距离) (。

rulerStyle

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

要应用的标尺样式。

返回

void

注解

API 集:WordApiDesktop 1.4

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Word.TableRowCollection 对象是 API 对象,但该 toJSON 方法返回一个纯 JavaScript 对象, (类型为 Word.Interfaces.TableRowCollectionData) ,其中包含一个“items”数组,其中包含从集合的 items 中加载的任何属性的浅层副本。

toJSON(): Word.Interfaces.TableRowCollectionData;

返回

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果在调用中 .sync 使用此对象,并且在“.run”批处理的顺序执行之外使用此对象,并且在设置属性或对对象调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪对象集合。 如果此对象是集合的一部分,您还应跟踪父集合。

track(): Word.TableRowCollection;

返回

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 需要在内存释放生效之前调用 context.sync()

untrack(): Word.TableRowCollection;

返回