Word.TableRow class

表示Word文档中的行。

Extends

注解

[ API 集:WordApi 1.3 ]

属性

cellCount

获取行中的单元格数。

cells

获取单元格。 此为只读属性。

context

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

endnotes

获取表行中的尾注集合。

fields

获取表行中的字段对象的集合。

font

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

footnotes

获取表行中的脚注集合。

horizontalAlignment

指定行中每个单元格的水平对齐方式。 该值可以是“Left”、“Centered”、“Right”或“Justified”。

isHeader

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

parentTable

获取父表。

preferredHeight

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

rowIndex

获取其父表中的行索引。

shadingColor

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

values

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

verticalAlignment

指定行中单元格的垂直对齐方式。 该值可以是“Top”、“Center”或“Bottom”。

方法

clear()

清除行内容。

delete()

删除整行。

getBorder(borderLocation)

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

getBorder(borderLocationString)

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

getCellPadding(cellPaddingLocation)

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

getCellPadding(cellPaddingLocationString)

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

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)

对行范围使用指定的 SearchOptions 执行搜索。 搜索结果是 range 对象的集合。

select(selectionMode)

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

select(selectionModeString)

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

set(properties, options)

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

set(properties)

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

setCellPadding(cellPaddingLocation, cellPadding)

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

setCellPadding(cellPaddingLocationString, cellPadding)

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

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 ]

context

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

context: RequestContext;

属性值

endnotes

获取表行中的尾注集合。

readonly endnotes: Word.NoteItemCollection;

属性值

注解

[ API 集:WordApi 1.5 ]

fields

获取表行中的字段对象的集合。

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

指定行中每个单元格的水平对齐方式。 该值可以是“Left”、“Centered”、“Right”或“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 ]

rowIndex

获取其父表中的行索引。

readonly rowIndex: number;

属性值

number

注解

[ API 集:WordApi 1.3 ]

shadingColor

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

shadingColor: string;

属性值

string

注解

[ API 集:WordApi 1.3 ]

values

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

values: string[][];

属性值

string[][]

注解

[ API 集:WordApi 1.3 ]

verticalAlignment

指定行中单元格的垂直对齐方式。 该值可以是“Top”、“Center”或“Bottom”。

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 ]

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 = context.document.body.tables.getFirst();
  const firstTableRow = firstTable.rows.getFirst();
  const borderLocation = Word.BorderLocation.bottom;
  const border = 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(borderLocationString)

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

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

参数

borderLocationString

"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

必填。 单元格填充位置必须为“Top”、“Left”、“Bottom”或“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 = context.document.body.tables.getFirst();
  const firstTableRow = 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(cellPaddingLocationString)

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

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

参数

cellPaddingLocationString

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

必需。 单元格填充位置必须为“Top”、“Left”、“Bottom”或“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()

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

在行中插入内容控件。

insertContentControl(): Word.ContentControl;

返回

注解

[ API 集:WordApi BETA (仅预览版) ]

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”或“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)

对行范围使用指定的 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”、“Start”或“End”。 “Select”为默认值。

返回

void

注解

[ API 集:WordApi 1.3 ]

select(selectionModeString)

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

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

参数

selectionModeString

"Select" | "Start" | "End"

可选。 选择模式必须为“Select”、“Start”或“End”。 “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

必填。 单元格填充位置必须为“Top”、“Left”、“Bottom”或“Right”。

cellPadding

number

必需。 单元格填充。

返回

void

注解

[ API 集:WordApi 1.3 ]

setCellPadding(cellPaddingLocationString, cellPadding)

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

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

参数

cellPaddingLocationString

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

必填。 单元格填充位置必须为“Top”、“Left”、“Bottom”或“Right”。

cellPadding

number

必需。 单元格填充。

返回

void

注解

[ API 集:WordApi 1.3 ]

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;

返回