Word.Table class

表示Word文档中的表。

Extends

注解

[ API 集:WordApi 1.3 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/table-cell-access.yaml

await Word.run(async (context) => {
  // Use a two-dimensional array to hold the initial table values.
  const data = [
    ["Tokyo", "Beijing", "Seattle"],
    ["Apple", "Orange", "Pineapple"]
  ];
  const table = context.document.body.insertTable(2, 3, "Start", data);
  table.styleBuiltIn = Word.BuiltInStyleName.gridTable5Dark_Accent2;
  table.styleFirstColumn = false;

  await context.sync();
});

属性

alignment

指定表与页面列的对齐方式。 该值可以是“Left”、“Centered”或“Right”。

context

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

endnotes

获取表中尾注的集合。

fields

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

font

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

footnotes

获取表中脚注的集合。

headerRowCount

指定标题行数。

horizontalAlignment

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

isUniform

指明所有表行是否一致。

nestingLevel

获取 table 的嵌套级别。 顶级 table 的级别为 1。

parentBody

获取 table 的父正文。

parentContentControl

获取包含 table 的 contentControl。 ItemNotFound如果没有父内容控件,则引发错误。

parentContentControlOrNullObject

获取包含 table 的 contentControl。 如果没有父内容控件,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

parentTable

获取包含此 table 的 table。 ItemNotFound如果未包含在表中,则引发错误。

parentTableCell

获取包含此 table 的 tableCell。 ItemNotFound如果表单元格中未包含错误,则引发错误。

parentTableCellOrNullObject

获取包含此 table 的 tableCell。 如果它未包含在表单元格中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

parentTableOrNullObject

获取包含此 table 的 table。 如果它未包含在表中,则此方法将返回一个 对象,其 isNullObject 属性设置为 true。 有关详细信息,请参阅 *OrNullObject 方法和属性

rowCount

获取表格中的行数。

rows

获取所有表格行。

shadingColor

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

style

指定表的样式名称。 请对自定义样式和本地化样式名称使用此属性。 若要使用可以在区域设置之间移植的嵌入样式,请参阅“styleBuiltIn”属性。

styleBandedColumns

指定表是否具有带状列。

styleBandedRows

指定表是否具有带带行。

styleBuiltIn

指定表的内置样式名称。 请对可以在区域设置之间移植的嵌入样式使用此属性。 若要使用自定义样式或本地化样式名称,请参阅“style”属性。

styleFirstColumn

指定表是否具有具有特殊样式的第一列。

styleLastColumn

指定表是否具有具有特殊样式的最后一列。

styleTotalRow

指定表是否具有具有特殊样式的最后一) 行的总 (。

tables

获取嵌套一级的子 table。

values

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

verticalAlignment

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

width

指定表的宽度(以磅为单位)。

方法

addColumns(insertLocation, columnCount, values)

使用第一个或最后一个现有列作为模板,将列添加到 table 的开头或结尾。 此方法适用于一致的 table。 字符串值(若指定)是在新插入的行中进行设置。

addRows(insertLocation, rowCount, values)

使用第一个或最后一个现有行作为模板,将行添加到 table 的开头或结尾。 字符串值(若指定)是在新插入的行中进行设置。

autoFitWindow()

自动调整表列,以适应窗口的宽度。

clear()

清除表内容。

delete()

删除整个表格。

deleteColumns(columnIndex, columnCount)

删除特定的列。 此方法适用于一致的 table。

deleteRows(rowIndex, rowCount)

删除特定的行。

distributeColumns()

将列设置为等宽。 此方法适用于一致的 table。

getBorder(borderLocation)

获取指定边框的边框样式。

getBorder(borderLocationString)

获取指定边框的边框样式。

getCell(rowIndex, cellIndex)

获取指定行和列处的表单元格。 ItemNotFound如果指定的表单元格不存在,则引发错误。

getCellOrNullObject(rowIndex, cellIndex)

获取指定行和列处的表单元格。 如果指定的表单元格不存在,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

getCellPadding(cellPaddingLocation)

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

getCellPadding(cellPaddingLocationString)

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

getNext()

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

getNextOrNullObject()

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

getParagraphAfter()

获取 table 之后的 paragraph。 ItemNotFound如果表后没有段落,则引发错误。

getParagraphAfterOrNullObject()

获取 table 之后的 paragraph。 如果表后没有段落,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

getParagraphBefore()

获取 table 之前的 paragraph。 ItemNotFound如果表前没有段落,则引发错误。

getParagraphBeforeOrNullObject()

获取 table 之前的 paragraph。 如果表前没有段落,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

getRange(rangeLocation)

获取包含此表格的范围,或包含此表格的开头或结尾的范围。

insertContentControl()

在表格中插入内容控件。

insertParagraph(paragraphText, insertLocation)

在指定位置插入段落。

insertTable(rowCount, columnCount, insertLocation, values)

插入包含指定行数和列数的 table。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

mergeCells(topRow, firstCell, bottomRow, lastCell)

合并由第一个单元格和最后一个单元格绑定的单元格。

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

track()

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

untrack()

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

属性详细信息

alignment

指定表与页面列的对齐方式。 该值可以是“Left”、“Centered”或“Right”。

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

属性值

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

注解

[ 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 alignment details about the first table in the document.
await Word.run(async (context) => {
  const firstTable = context.document.body.tables.getFirst();
  firstTable.load(["alignment", "horizontalAlignment", "verticalAlignment"]);
  await context.sync();

  console.log(`Details about the alignment of the first table:`);
  console.log(`- Alignment of the table within the containing page column: ${firstTable.alignment}`);
  console.log(`- Horizontal alignment of every cell in the table: ${firstTable.horizontalAlignment}`);
  console.log(`- Vertical alignment of every cell in the table: ${firstTable.verticalAlignment}`);
});

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 ]

headerRowCount

指定标题行数。

headerRowCount: number;

属性值

number

注解

[ API 集:WordApi 1.3 ]

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 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml

// Gets alignment details about the first table in the document.
await Word.run(async (context) => {
  const firstTable = context.document.body.tables.getFirst();
  firstTable.load(["alignment", "horizontalAlignment", "verticalAlignment"]);
  await context.sync();

  console.log(`Details about the alignment of the first table:`);
  console.log(`- Alignment of the table within the containing page column: ${firstTable.alignment}`);
  console.log(`- Horizontal alignment of every cell in the table: ${firstTable.horizontalAlignment}`);
  console.log(`- Vertical alignment of every cell in the table: ${firstTable.verticalAlignment}`);
});

isUniform

指明所有表行是否一致。

readonly isUniform: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.3 ]

nestingLevel

获取 table 的嵌套级别。 顶级 table 的级别为 1。

readonly nestingLevel: number;

属性值

number

注解

[ API 集:WordApi 1.3 ]

parentBody

获取 table 的父正文。

readonly parentBody: Word.Body;

属性值

注解

[ API 集:WordApi 1.3 ]

parentContentControl

获取包含 table 的 contentControl。 ItemNotFound如果没有父内容控件,则引发错误。

readonly parentContentControl: Word.ContentControl;

属性值

注解

[ API 集:WordApi 1.3 ]

parentContentControlOrNullObject

获取包含 table 的 contentControl。 如果没有父内容控件,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly parentContentControlOrNullObject: Word.ContentControl;

属性值

注解

[ API 集:WordApi 1.3 ]

parentTable

获取包含此 table 的 table。 ItemNotFound如果未包含在表中,则引发错误。

readonly parentTable: Word.Table;

属性值

注解

[ API 集:WordApi 1.3 ]

parentTableCell

获取包含此 table 的 tableCell。 ItemNotFound如果表单元格中未包含错误,则引发错误。

readonly parentTableCell: Word.TableCell;

属性值

注解

[ API 集:WordApi 1.3 ]

parentTableCellOrNullObject

获取包含此 table 的 tableCell。 如果它未包含在表单元格中,则此方法将返回其 isNullObject 属性设置为 true的对象。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly parentTableCellOrNullObject: Word.TableCell;

属性值

注解

[ API 集:WordApi 1.3 ]

parentTableOrNullObject

获取包含此 table 的 table。 如果它未包含在表中,则此方法将返回一个 对象,其 isNullObject 属性设置为 true。 有关详细信息,请参阅 *OrNullObject 方法和属性

readonly parentTableOrNullObject: Word.Table;

属性值

注解

[ API 集:WordApi 1.3 ]

rowCount

获取表格中的行数。

readonly rowCount: number;

属性值

number

注解

[ API 集:WordApi 1.3 ]

rows

获取所有表格行。

readonly rows: Word.TableRowCollection;

属性值

注解

[ 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 = context.document.body.tables.getFirst();
  const firstTableRow = firstTable.rows.getFirst();
  firstTableRow.load(["horizontalAlignment", "verticalAlignment"]);
  await context.sync();

  console.log(`Details about the alignment of the first table's first row:`);
  console.log(`- Horizontal alignment of every cell in the row: ${firstTableRow.horizontalAlignment}`);
  console.log(`- Vertical alignment of every cell in the row: ${firstTableRow.verticalAlignment}`);
});

shadingColor

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

shadingColor: string;

属性值

string

注解

[ API 集:WordApi 1.3 ]

style

指定表的样式名称。 请对自定义样式和本地化样式名称使用此属性。 若要使用可以在区域设置之间移植的嵌入样式,请参阅“styleBuiltIn”属性。

style: string;

属性值

string

注解

[ API 集:WordApi 1.3 ]

styleBandedColumns

指定表是否具有带状列。

styleBandedColumns: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.3 ]

styleBandedRows

指定表是否具有带带行。

styleBandedRows: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.3 ]

styleBuiltIn

指定表的内置样式名称。 请对可以在区域设置之间移植的嵌入样式使用此属性。 若要使用自定义样式或本地化样式名称,请参阅“style”属性。

styleBuiltIn: Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6";

属性值

Word.BuiltInStyleName | "Other" | "Normal" | "Heading1" | "Heading2" | "Heading3" | "Heading4" | "Heading5" | "Heading6" | "Heading7" | "Heading8" | "Heading9" | "Toc1" | "Toc2" | "Toc3" | "Toc4" | "Toc5" | "Toc6" | "Toc7" | "Toc8" | "Toc9" | "FootnoteText" | "Header" | "Footer" | "Caption" | "FootnoteReference" | "EndnoteReference" | "EndnoteText" | "Title" | "Subtitle" | "Hyperlink" | "Strong" | "Emphasis" | "NoSpacing" | "ListParagraph" | "Quote" | "IntenseQuote" | "SubtleEmphasis" | "IntenseEmphasis" | "SubtleReference" | "IntenseReference" | "BookTitle" | "Bibliography" | "TocHeading" | "TableGrid" | "PlainTable1" | "PlainTable2" | "PlainTable3" | "PlainTable4" | "PlainTable5" | "TableGridLight" | "GridTable1Light" | "GridTable1Light_Accent1" | "GridTable1Light_Accent2" | "GridTable1Light_Accent3" | "GridTable1Light_Accent4" | "GridTable1Light_Accent5" | "GridTable1Light_Accent6" | "GridTable2" | "GridTable2_Accent1" | "GridTable2_Accent2" | "GridTable2_Accent3" | "GridTable2_Accent4" | "GridTable2_Accent5" | "GridTable2_Accent6" | "GridTable3" | "GridTable3_Accent1" | "GridTable3_Accent2" | "GridTable3_Accent3" | "GridTable3_Accent4" | "GridTable3_Accent5" | "GridTable3_Accent6" | "GridTable4" | "GridTable4_Accent1" | "GridTable4_Accent2" | "GridTable4_Accent3" | "GridTable4_Accent4" | "GridTable4_Accent5" | "GridTable4_Accent6" | "GridTable5Dark" | "GridTable5Dark_Accent1" | "GridTable5Dark_Accent2" | "GridTable5Dark_Accent3" | "GridTable5Dark_Accent4" | "GridTable5Dark_Accent5" | "GridTable5Dark_Accent6" | "GridTable6Colorful" | "GridTable6Colorful_Accent1" | "GridTable6Colorful_Accent2" | "GridTable6Colorful_Accent3" | "GridTable6Colorful_Accent4" | "GridTable6Colorful_Accent5" | "GridTable6Colorful_Accent6" | "GridTable7Colorful" | "GridTable7Colorful_Accent1" | "GridTable7Colorful_Accent2" | "GridTable7Colorful_Accent3" | "GridTable7Colorful_Accent4" | "GridTable7Colorful_Accent5" | "GridTable7Colorful_Accent6" | "ListTable1Light" | "ListTable1Light_Accent1" | "ListTable1Light_Accent2" | "ListTable1Light_Accent3" | "ListTable1Light_Accent4" | "ListTable1Light_Accent5" | "ListTable1Light_Accent6" | "ListTable2" | "ListTable2_Accent1" | "ListTable2_Accent2" | "ListTable2_Accent3" | "ListTable2_Accent4" | "ListTable2_Accent5" | "ListTable2_Accent6" | "ListTable3" | "ListTable3_Accent1" | "ListTable3_Accent2" | "ListTable3_Accent3" | "ListTable3_Accent4" | "ListTable3_Accent5" | "ListTable3_Accent6" | "ListTable4" | "ListTable4_Accent1" | "ListTable4_Accent2" | "ListTable4_Accent3" | "ListTable4_Accent4" | "ListTable4_Accent5" | "ListTable4_Accent6" | "ListTable5Dark" | "ListTable5Dark_Accent1" | "ListTable5Dark_Accent2" | "ListTable5Dark_Accent3" | "ListTable5Dark_Accent4" | "ListTable5Dark_Accent5" | "ListTable5Dark_Accent6" | "ListTable6Colorful" | "ListTable6Colorful_Accent1" | "ListTable6Colorful_Accent2" | "ListTable6Colorful_Accent3" | "ListTable6Colorful_Accent4" | "ListTable6Colorful_Accent5" | "ListTable6Colorful_Accent6" | "ListTable7Colorful" | "ListTable7Colorful_Accent1" | "ListTable7Colorful_Accent2" | "ListTable7Colorful_Accent3" | "ListTable7Colorful_Accent4" | "ListTable7Colorful_Accent5" | "ListTable7Colorful_Accent6"

注解

[ API 集:WordApi 1.3 ]

styleFirstColumn

指定表是否具有具有特殊样式的第一列。

styleFirstColumn: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.3 ]

styleLastColumn

指定表是否具有具有特殊样式的最后一列。

styleLastColumn: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.3 ]

styleTotalRow

指定表是否具有具有特殊样式的最后一) 行的总 (。

styleTotalRow: boolean;

属性值

boolean

注解

[ API 集:WordApi 1.3 ]

tables

获取嵌套一级的子 table。

readonly tables: Word.TableCollection;

属性值

注解

[ 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 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/manage-formatting.yaml

// Gets alignment details about the first table in the document.
await Word.run(async (context) => {
  const firstTable = context.document.body.tables.getFirst();
  firstTable.load(["alignment", "horizontalAlignment", "verticalAlignment"]);
  await context.sync();

  console.log(`Details about the alignment of the first table:`);
  console.log(`- Alignment of the table within the containing page column: ${firstTable.alignment}`);
  console.log(`- Horizontal alignment of every cell in the table: ${firstTable.horizontalAlignment}`);
  console.log(`- Vertical alignment of every cell in the table: ${firstTable.verticalAlignment}`);
});

width

指定表的宽度(以磅为单位)。

width: number;

属性值

number

注解

[ API 集:WordApi 1.3 ]

方法详细信息

addColumns(insertLocation, columnCount, values)

使用第一个或最后一个现有列作为模板,将列添加到 table 的开头或结尾。 此方法适用于一致的 table。 字符串值(若指定)是在新插入的行中进行设置。

addColumns(insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End", columnCount: number, values?: string[][]): void;

参数

insertLocation

start | end | "Start" | "End"

必填。 它必须是“Start”或“End”,对应于表的相应端。

columnCount

number

必需。 要添加的列数。

values

string[][]

可选的二维数组。 如果指定数组中的对应字符串,则填充单元格。

返回

void

注解

[ API 集:WordApi 1.3 ]

addRows(insertLocation, rowCount, values)

使用第一个或最后一个现有行作为模板,将行添加到 table 的开头或结尾。 字符串值(若指定)是在新插入的行中进行设置。

addRows(insertLocation: Word.InsertLocation.start | Word.InsertLocation.end | "Start" | "End", rowCount: number, values?: string[][]): Word.TableRowCollection;

参数

insertLocation

start | end | "Start" | "End"

必填。 它必须是“Start”或“End”。

rowCount

number

必填。 要添加的行数。

values

string[][]

可选的二维数组。 如果指定数组中的对应字符串,则填充单元格。

返回

注解

[ API 集:WordApi 1.3 ]

autoFitWindow()

自动调整表列,以适应窗口的宽度。

autoFitWindow(): void;

返回

void

注解

[ API 集:WordApi 1.3 ]

clear()

清除表内容。

clear(): void;

返回

void

注解

[ API 集:WordApi 1.3 ]

delete()

删除整个表格。

delete(): void;

返回

void

注解

[ API 集:WordApi 1.3 ]

deleteColumns(columnIndex, columnCount)

删除特定的列。 此方法适用于一致的 table。

deleteColumns(columnIndex: number, columnCount?: number): void;

参数

columnIndex

number

必需。 要删除的第一列。

columnCount

number

可选。 要删除的列数。 默认值 1。

返回

void

注解

[ API 集:WordApi 1.3 ]

deleteRows(rowIndex, rowCount)

删除特定的行。

deleteRows(rowIndex: number, rowCount?: number): void;

参数

rowIndex

number

必需。 要删除的第一行。

rowCount

number

可选。 要删除的行数。 默认值 1。

返回

void

注解

[ API 集:WordApi 1.3 ]

distributeColumns()

将列设置为等宽。 此方法适用于一致的 table。

distributeColumns(): 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 table in the document.
await Word.run(async (context) => {
  const firstTable = context.document.body.tables.getFirst();
  const borderLocation = Word.BorderLocation.top;
  const border = firstTable.getBorder(borderLocation);
  border.load(["type", "color", "width"]);
  await context.sync();

  console.log(`Details about the ${borderLocation} border of the first table:`);
  console.log(`- Color: ${border.color}`);
  console.log(`- Type: ${border.type}`);
  console.log(`- 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 ]

getCell(rowIndex, cellIndex)

获取指定行和列处的表单元格。 ItemNotFound如果指定的表单元格不存在,则引发错误。

getCell(rowIndex: number, cellIndex: number): Word.TableCell;

参数

rowIndex

number

必填。 行的索引。

cellIndex

number

必填。 行中单元格的索引。

返回

注解

[ API 集:WordApi 1.3 ]

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/40-tables/table-cell-access.yaml

// Gets the content of the first cell in the first table.
await Word.run(async (context) => {
  const firstCell = context.document.body.tables.getFirst().getCell(0, 0).body;
  firstCell.load("text");

  await context.sync();
  console.log("First cell's text is: " + firstCell.text);
});

getCellOrNullObject(rowIndex, cellIndex)

获取指定行和列处的表单元格。 如果指定的表单元格不存在,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

getCellOrNullObject(rowIndex: number, cellIndex: number): Word.TableCell;

参数

rowIndex

number

必需。 行的索引。

cellIndex

number

必需。 行中单元格的索引。

返回

注解

[ 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 table in the document.
await Word.run(async (context) => {
  const firstTable = context.document.body.tables.getFirst();
  const cellPaddingLocation = Word.CellPaddingLocation.right;
  const cellPadding = firstTable.getCellPadding(cellPaddingLocation);
  await context.sync();

  console.log(
    `Cell padding details about the ${cellPaddingLocation} border of the first table: ${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.Table;

返回

注解

[ API 集:WordApi 1.3 ]

getNextOrNullObject()

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

getNextOrNullObject(): Word.Table;

返回

注解

[ API 集:WordApi 1.3 ]

getParagraphAfter()

获取 table 之后的 paragraph。 ItemNotFound如果表后没有段落,则引发错误。

getParagraphAfter(): Word.Paragraph;

返回

注解

[ API 集:WordApi 1.3 ]

getParagraphAfterOrNullObject()

获取 table 之后的 paragraph。 如果表后没有段落,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

getParagraphAfterOrNullObject(): Word.Paragraph;

返回

注解

[ API 集:WordApi 1.3 ]

getParagraphBefore()

获取 table 之前的 paragraph。 ItemNotFound如果表前没有段落,则引发错误。

getParagraphBefore(): Word.Paragraph;

返回

注解

[ API 集:WordApi 1.3 ]

getParagraphBeforeOrNullObject()

获取 table 之前的 paragraph。 如果表前没有段落,则此方法将返回其属性设置为 true的对象isNullObject。 有关详细信息,请参阅 *OrNullObject 方法和属性

getParagraphBeforeOrNullObject(): Word.Paragraph;

返回

注解

[ API 集:WordApi 1.3 ]

getRange(rangeLocation)

获取包含此表格的范围,或包含此表格的开头或结尾的范围。

getRange(rangeLocation?: Word.RangeLocation.whole | Word.RangeLocation.start | Word.RangeLocation.end | Word.RangeLocation.after | "Whole" | "Start" | "End" | "After"): Word.Range;

参数

rangeLocation

whole | start | end | after | "Whole" | "Start" | "End" | "After"

可选。 范围位置必须为“Whole”、“Start”、“End”或“After”。

返回

注解

[ API 集:WordApi 1.3 ]

insertContentControl()

在表格中插入内容控件。

insertContentControl(): Word.ContentControl;

返回

注解

[ API 集:WordApi 1.3 ]

insertParagraph(paragraphText, insertLocation)

在指定位置插入段落。

insertParagraph(paragraphText: string, insertLocation: Word.InsertLocation.before | Word.InsertLocation.after | "Before" | "After"): Word.Paragraph;

参数

paragraphText

string

必需。 要插入的段落文本。

insertLocation

before | after | "Before" | "After"

必填。 该值必须为“Before”或“After”。

返回

注解

[ API 集:WordApi 1.3 ]

insertTable(rowCount, columnCount, insertLocation, values)

插入包含指定行数和列数的 table。

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

参数

rowCount

number

必填。 表格的行数。

columnCount

number

必需。 表格的列数。

insertLocation

before | after | "Before" | "After"

必填。 该值必须为“Before”或“After”。

values

string[][]

可选的二维数组。 如果指定数组中的对应字符串,则填充单元格。

返回

注解

[ API 集:WordApi 1.3 ]

load(options)

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

load(options?: Word.Interfaces.TableLoadOptions): Word.Table;

参数

options
Word.Interfaces.TableLoadOptions

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

返回

load(propertyNames)

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

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

参数

propertyNames

string | string[]

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

返回

load(propertyNamesAndPaths)

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

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

参数

propertyNamesAndPaths

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

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

返回

mergeCells(topRow, firstCell, bottomRow, lastCell)

合并由第一个单元格和最后一个单元格绑定的单元格。

mergeCells(topRow: number, firstCell: number, bottomRow: number, lastCell: number): Word.TableCell;

参数

topRow

number

必需。 第一个单元格的行

firstCell

number

必需。 行中第一个单元格的索引

bottomRow

number

必填。 最后一个单元格的行

lastCell

number

必需。 行中最后一个单元格的索引

返回

注解

[ 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.TableUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Word.Interfaces.TableUpdateData

一个 JavaScript 对象,其属性按同构方式构造为调用方法的对象的属性。

options
OfficeExtension.UpdateOptions

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

返回

void

set(properties)

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

set(properties: Word.Table): void;

参数

properties
Word.Table

返回

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

toJSON(): Word.Interfaces.TableData;

返回

track()

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

track(): Word.Table;

返回

untrack()

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

untrack(): Word.Table;

返回