PowerPoint.TableCell class

表示一个表。

扩展

注解

API 集:PowerPointApi 1.8

使用方

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/add-modify-tables.yaml

// Updates a table's values.
await PowerPoint.run(async (context) => {
  const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;

  // Add a table (which is a type of Shape).
  const shape = shapes.addTable(4, 3);
  let table = shape.getTable();
  table.load();
  await context.sync();

  // Update values in the table.
  for (let rowIndex = 0; rowIndex < table.rowCount; rowIndex++) {
    for (let columnIndex = 0; columnIndex < table.columnCount; columnIndex++) {
      const cell = table.getCellOrNullObject(rowIndex, columnIndex);
      cell.text = generateRandomString();
    }
  }

  await context.sync();
});

属性

borders

获取表格单元格的边框集合。

columnCount

获取此单元格跨越的表列数。 将大于或等于 1。

columnIndex

获取表中单元格的从零开始的列索引。

context

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

fill

获取表格单元格的填充颜色。

font

获取表格单元格的字体。

horizontalAlignment

指定表格单元格中文本的水平对齐方式。 如果单元格文本包含不同的对齐方式,则返回 null

indentLevel

指定表格单元格中文本的缩进级别。 单元格文本包含不同的缩进级别时返回 null

margins

获取表单元格中的边距集。

rowCount

获取此单元格跨越的表行数。 将大于或等于 1。

rowIndex

获取表中单元格的从零开始的行索引。

text

指定表单元格的文本内容。

textRuns

将表格单元格的内容指定为 PowerPoint.TextRun 对象的数组。 每个 TextRun 对象表示一个或多个具有相同字体属性的字符序列。

verticalAlignment

指定表格单元格中文本的垂直对齐方式。

方法

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

resize(rowCount, columnCount)

调整表单元格的大小,使其跨指定行数和列数。 如果 rowCount 或 columnCount 大于 1,单元格将成为合并区域。 如果单元格已经是合并区域,并且 rowCount 和 columnCount 设置为 1,则该单元格将不再是合并区域。

split(rowCount, columnCount)

将单元格拆分为指定行数和列数。

toJSON()

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

属性详细信息

borders

获取表格单元格的边框集合。

readonly borders: PowerPoint.Borders;

属性值

注解

API 集:PowerPointApi 1.9

columnCount

获取此单元格跨越的表列数。 将大于或等于 1。

readonly columnCount: number;

属性值

number

注解

API 集:PowerPointApi 1.8

columnIndex

获取表中单元格的从零开始的列索引。

readonly columnIndex: number;

属性值

number

注解

API 集:PowerPointApi 1.8

context

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

context: RequestContext;

属性值

fill

获取表格单元格的填充颜色。

readonly fill: PowerPoint.ShapeFill;

属性值

注解

API 集:PowerPointApi 1.9

font

获取表格单元格的字体。

readonly font: PowerPoint.ShapeFont;

属性值

注解

API 集:PowerPointApi 1.9

horizontalAlignment

指定表格单元格中文本的水平对齐方式。 如果单元格文本包含不同的对齐方式,则返回 null

horizontalAlignment: PowerPoint.ParagraphHorizontalAlignment | "Left" | "Center" | "Right" | "Justify" | "JustifyLow" | "Distributed" | "ThaiDistributed" | null;

属性值

PowerPoint.ParagraphHorizontalAlignment | "Left" | "Center" | "Right" | "Justify" | "JustifyLow" | "Distributed" | "ThaiDistributed" | null

注解

API 集:PowerPointApi 1.9

indentLevel

指定表格单元格中文本的缩进级别。 单元格文本包含不同的缩进级别时返回 null

indentLevel: number | null;

属性值

number | null

注解

API 集:PowerPointApi 1.9

margins

获取表单元格中的边距集。

readonly margins: PowerPoint.Margins;

属性值

注解

API 集:PowerPointApi 1.9

rowCount

获取此单元格跨越的表行数。 将大于或等于 1。

readonly rowCount: number;

属性值

number

注解

API 集:PowerPointApi 1.8

rowIndex

获取表中单元格的从零开始的行索引。

readonly rowIndex: number;

属性值

number

注解

API 集:PowerPointApi 1.8

text

指定表单元格的文本内容。

text: string;

属性值

string

注解

API 集:PowerPointApi 1.8

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/add-modify-tables.yaml

// Updates a table's values.
await PowerPoint.run(async (context) => {
  const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;

  // Add a table (which is a type of Shape).
  const shape = shapes.addTable(4, 3);
  let table = shape.getTable();
  table.load();
  await context.sync();

  // Update values in the table.
  for (let rowIndex = 0; rowIndex < table.rowCount; rowIndex++) {
    for (let columnIndex = 0; columnIndex < table.columnCount; columnIndex++) {
      const cell = table.getCellOrNullObject(rowIndex, columnIndex);
      cell.text = generateRandomString();
    }
  }

  await context.sync();
});

textRuns

将表格单元格的内容指定为 PowerPoint.TextRun 对象的数组。 每个 TextRun 对象表示一个或多个具有相同字体属性的字符序列。

textRuns: PowerPoint.TextRun[];

属性值

注解

API 集:PowerPointApi 1.9

verticalAlignment

指定表格单元格中文本的垂直对齐方式。

verticalAlignment: PowerPoint.TextVerticalAlignment | "Top" | "Middle" | "Bottom" | "TopCentered" | "MiddleCentered" | "BottomCentered";

属性值

PowerPoint.TextVerticalAlignment | "Top" | "Middle" | "Bottom" | "TopCentered" | "MiddleCentered" | "BottomCentered"

注解

API 集:PowerPointApi 1.9

方法详细信息

load(options)

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

load(options?: PowerPoint.Interfaces.TableCellLoadOptions): PowerPoint.TableCell;

参数

options
PowerPoint.Interfaces.TableCellLoadOptions

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

返回

load(propertyNames)

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

load(propertyNames?: string | string[]): PowerPoint.TableCell;

参数

propertyNames

string | string[]

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

返回

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.TableCell;

参数

propertyNamesAndPaths

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

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

返回

resize(rowCount, columnCount)

调整表单元格的大小,使其跨指定行数和列数。 如果 rowCount 或 columnCount 大于 1,单元格将成为合并区域。 如果单元格已经是合并区域,并且 rowCount 和 columnCount 设置为 1,则该单元格将不再是合并区域。

resize(rowCount: number, columnCount: number): void;

参数

rowCount

number

单元格将跨越的行数。 必须大于 0。

columnCount

number

单元格将跨越的列数。 必须大于 0。

返回

void

注解

API 集:PowerPointApi 1.9

split(rowCount, columnCount)

将单元格拆分为指定行数和列数。

split(rowCount: number, columnCount: number): void;

参数

rowCount

number

要拆分为的行数。 必须大于 0。

columnCount

number

要拆分为的列数。 必须大于 0。

返回

void

注解

API 集:PowerPointApi 1.9

toJSON()

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

toJSON(): PowerPoint.Interfaces.TableCellData;

返回