Word.TableRow class

表示 Word 文档中的行。

扩展

注解

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

属性

cellCount

获取行中的单元格数。

cells

获取单元格。

context

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

endnotes

获取表行中的尾注集合。

fields

获取表行中的对象集合 Field

font

获取字体。 使用此关系可获取并设置字体名称、大小、颜色和其他属性。

footnotes

获取表行中的脚注集合。

horizontalAlignment

指定行中每个单元格的水平对齐方式。 值可以是 leftcenteredright 或 。justified

isHeader

检查该行是否为标题行。 若要设置标题行数,请在对象上Table使用headerRowCount

parentTable

获取父表。

preferredHeight

指定行的首选高度(以磅为单位)。

range

返回 Range 表示表行的对象。

rowIndex

获取其父表中的行索引。

shading

返回 ShadingUniversal 表示表行底纹的对象。

shadingColor

指定底纹颜色。 按“#RRGGBB”格式或使用颜色名称指定颜色。

values

将行中的文本值指定为 2D JavaScript 数组。

verticalAlignment

指定行中单元格的垂直对齐方式。 值可以是 topcenterbottom

方法

clear()

清除行内容。

convertToText(options)

将表格行转换为文本。

delete()

删除整行。

getBorder(borderLocation)

获取行中单元格的边框样式。

getBorder(borderLocation)

获取行中单元格的边框样式。

getCellPadding(cellPaddingLocation)

获取单元格填充(以磅为单位)。

getCellPadding(cellPaddingLocation)

获取单元格填充(以磅为单位)。

getNext()

获取下一行。 如果此行是最后一行,则引发 ItemNotFound 错误。

getNextOrNullObject()

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

insertContentControl()

在行中插入内容控件。

insertRows(insertLocation, rowCount, values)

使用此行作为模板插入行。 如果值已指定,请将值插入新行。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

merge()

将该行合并为一个单元格。

search(searchText, searchOptions)

使用指定的搜索选项对行范围执行搜索。 搜索结果是对象的 Range 集合。

select(selectionMode)

选择行,然后将 Word UI 导航到相应位置。

select(selectionMode)

选择行,然后将 Word UI 导航到相应位置。

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。

set(properties)

基于现有加载的对象,同时在对象上设置多个属性。

setCellPadding(cellPaddingLocation, cellPadding)

设置单元格填充(以磅为单位)。

setCellPadding(cellPaddingLocation, cellPadding)

设置单元格填充(以磅为单位)。

setHeight(rowHeight, heightRule)

设置行高。

setHeight(rowHeight, heightRule)

设置行高。

setLeftIndent(leftIndent, rulerStyle)

设置表行的左缩进。

setLeftIndent(leftIndent, rulerStyle)

设置表行的左缩进。

toJSON()

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

track()

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

untrack()

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

属性详细信息

cellCount

获取行中的单元格数。

readonly cellCount: number;

属性值

number

注解

API 集:WordApi 1.3

cells

获取单元格。

readonly cells: Word.TableCellCollection;

属性值

注解

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

context

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

context: RequestContext;

属性值

endnotes

获取表行中的尾注集合。

readonly endnotes: Word.NoteItemCollection;

属性值

注解

API 集:WordApi 1.5

fields

获取表行中的对象集合 Field

readonly fields: Word.FieldCollection;

属性值

注解

API 集:WordApi 1.4

font

获取字体。 使用此关系可获取并设置字体名称、大小、颜色和其他属性。

readonly font: Word.Font;

属性值

注解

API 集:WordApi 1.3

footnotes

获取表行中的脚注集合。

readonly footnotes: Word.NoteItemCollection;

属性值

注解

API 集:WordApi 1.5

horizontalAlignment

指定行中每个单元格的水平对齐方式。 值可以是 leftcenteredright 或 。justified

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

属性值

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

注解

API 集:WordApi 1.3

isHeader

检查该行是否为标题行。 若要设置标题行数,请在对象上Table使用headerRowCount

readonly isHeader: boolean;

属性值

boolean

注解

API 集:WordApi 1.3

parentTable

获取父表。

readonly parentTable: Word.Table;

属性值

注解

API 集:WordApi 1.3

preferredHeight

指定行的首选高度(以磅为单位)。

preferredHeight: number;

属性值

number

注解

API 集:WordApi 1.3

range

返回 Range 表示表行的对象。

readonly range: Word.Range;

属性值

注解

API 集:WordApiDesktop 1.4

rowIndex

获取其父表中的行索引。

readonly rowIndex: number;

属性值

number

注解

API 集:WordApi 1.3

shading

返回 ShadingUniversal 表示表行底纹的对象。

readonly shading: Word.ShadingUniversal;

属性值

注解

API 集:WordApiDesktop 1.4

shadingColor

指定底纹颜色。 按“#RRGGBB”格式或使用颜色名称指定颜色。

shadingColor: string;

属性值

string

注解

API 集:WordApi 1.3

values

将行中的文本值指定为 2D JavaScript 数组。

values: string[][];

属性值

string[][]

注解

API 集:WordApi 1.3

verticalAlignment

指定行中单元格的垂直对齐方式。 值可以是 topcenterbottom

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

属性值

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

注解

API 集:WordApi 1.3

方法详细信息

clear()

清除行内容。

clear(): void;

返回

void

注解

API 集:WordApi 1.3

convertToText(options)

将表格行转换为文本。

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

参数

options
Word.TableConvertToTextOptions

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

返回

注解

API 集:WordApiDesktop 1.4

delete()

删除整行。

delete(): void;

返回

void

注解

API 集:WordApi 1.3

getBorder(borderLocation)

获取行中单元格的边框样式。

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

参数

borderLocation
Word.BorderLocation

边框位置。

返回

注解

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

getBorder(borderLocation)

获取行中单元格的边框样式。

getBorder(borderLocation: "Top" | "Left" | "Bottom" | "Right" | "InsideHorizontal" | "InsideVertical" | "Inside" | "Outside" | "All"): Word.TableBorder;

参数

borderLocation

"Top" | "Left" | "Bottom" | "Right" | "InsideHorizontal" | "InsideVertical" | "Inside" | "Outside" | "All"

边框位置。

返回

注解

API 集:WordApi 1.3

getCellPadding(cellPaddingLocation)

获取单元格填充(以磅为单位)。

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

参数

cellPaddingLocation
Word.CellPaddingLocation

单元格填充位置必须是 topleftbottom 或 。right

返回

注解

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 cell padding 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 cellPaddingLocation = Word.CellPaddingLocation.bottom;
  const cellPadding = firstTableRow.getCellPadding(cellPaddingLocation);
  await context.sync();

  console.log(
    `Cell padding details about the ${cellPaddingLocation} border of the first table's first row: ${cellPadding.value} points`,
  );
});

getCellPadding(cellPaddingLocation)

获取单元格填充(以磅为单位)。

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

参数

cellPaddingLocation

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

单元格填充位置必须是 topleftbottom 或 。right

返回

注解

API 集:WordApi 1.3

getNext()

获取下一行。 如果此行是最后一行,则引发 ItemNotFound 错误。

getNext(): Word.TableRow;

返回

注解

API 集:WordApi 1.3

getNextOrNullObject()

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

getNextOrNullObject(): Word.TableRow;

返回

注解

API 集:WordApi 1.3

insertContentControl()

在行中插入内容控件。

insertContentControl(): Word.ContentControl;

返回

注解

API 集:WordApiDesktop 1.1

insertRows(insertLocation, rowCount, values)

使用此行作为模板插入行。 如果值已指定,请将值插入新行。

insertRows(insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After", rowCount: number, values?: string[][]): Word.TableRowCollection;

参数

insertLocation

before | after | "Before" | "After"

相对于当前行应插入新行的位置。 它必须是 before OR after

rowCount

number

要添加的行数。

values

string[][]

可选。 要插入到新行中的字符串,指定为 2D 数组。 每行中的单元格数不得超过现有行中的单元格数。

返回

注解

API 集:WordApi 1.3

load(options)

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

load(options?: Word.Interfaces.TableRowLoadOptions): Word.TableRow;

参数

options
Word.Interfaces.TableRowLoadOptions

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

返回

load(propertyNames)

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

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

参数

propertyNames

string | string[]

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

返回

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.TableRow;

参数

propertyNamesAndPaths

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

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

返回

merge()

将该行合并为一个单元格。

merge(): Word.TableCell;

返回

注解

API 集:WordApi 1.4

search(searchText, searchOptions)

使用指定的搜索选项对行范围执行搜索。 搜索结果是对象的 Range 集合。

search(searchText: string, searchOptions?: Word.SearchOptions | {
            ignorePunct?: boolean;
            ignoreSpace?: boolean;
            matchCase?: boolean;
            matchPrefix?: boolean;
            matchSuffix?: boolean;
            matchWholeWord?: boolean;
            matchWildcards?: boolean;
        }): Word.RangeCollection;

参数

searchText

string

搜索文本。

searchOptions

Word.SearchOptions | { ignorePunct?: boolean; ignoreSpace?: boolean; matchCase?: boolean; matchPrefix?: boolean; matchSuffix?: boolean; matchWholeWord?: boolean; matchWildcards?: boolean; }

可选。 用于搜索的选项。

返回

注解

API 集:WordApi 1.3

select(selectionMode)

选择行,然后将 Word UI 导航到相应位置。

select(selectionMode?: Word.SelectionMode): void;

参数

selectionMode
Word.SelectionMode

可选。 选择模式必须为 select、 、startend select 为默认值。

返回

void

注解

API 集:WordApi 1.3

select(selectionMode)

选择行,然后将 Word UI 导航到相应位置。

select(selectionMode?: "Select" | "Start" | "End"): void;

参数

selectionMode

"Select" | "Start" | "End"

可选。 选择模式必须为 select、 、startend select 为默认值。

返回

void

注解

API 集:WordApi 1.3

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。

set(properties: Interfaces.TableRowUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Word.Interfaces.TableRowUpdateData

一个 JavaScript 对象,其属性与调用该方法的对象的属性同构结构。

options
OfficeExtension.UpdateOptions

提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止错误。

返回

void

set(properties)

基于现有加载的对象,同时在对象上设置多个属性。

set(properties: Word.TableRow): void;

参数

properties
Word.TableRow

返回

void

setCellPadding(cellPaddingLocation, cellPadding)

设置单元格填充(以磅为单位)。

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

参数

cellPaddingLocation
Word.CellPaddingLocation

单元格填充位置必须是 topleftbottom 或 。right

cellPadding

number

单元格填充。

返回

void

注解

API 集:WordApi 1.3

setCellPadding(cellPaddingLocation, cellPadding)

设置单元格填充(以磅为单位)。

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

参数

cellPaddingLocation

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

单元格填充位置必须是 topleftbottom 或 。right

cellPadding

number

单元格填充。

返回

void

注解

API 集:WordApi 1.3

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.TableRow 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Word.Interfaces.TableRowData) ,其中包含从原始对象加载的任何子属性的浅层副本。

toJSON(): Word.Interfaces.TableRowData;

返回

track()

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

track(): Word.TableRow;

返回

untrack()

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

untrack(): Word.TableRow;

返回