PowerPoint.Table class
表示一个表。
注解
使用方
示例
// 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();
});
属性
| column |
获取表中的列数。 |
| columns | 获取表中列的集合。 |
| context | 与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。 |
| row |
获取表格中的行数。 |
| rows | 获取表中行的集合。 |
| style |
获取表格样式设置。 |
| values | 获取表中的所有值。 |
方法
| clear(options) | 清除表值和格式。 |
| get |
获取指定 |
| get |
获取表示表的合并区域的单元格集合。 |
| get |
获取表格的形状对象。 |
| load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
| merge |
从 rowIndex 和 columnIndex 指定的单元格开始创建一个合并区域。 合并区域跨越指定数量的行数和列数。 |
| toJSON() | 覆盖 JavaScript |
属性详细信息
columnCount
columns
获取表中列的集合。
readonly columns: PowerPoint.TableColumnCollection;
属性值
注解
context
rowCount
rows
获取表中行的集合。
readonly rows: PowerPoint.TableRowCollection;
属性值
注解
styleSettings
获取表格样式设置。
readonly styleSettings: PowerPoint.TableStyleSettings;
属性值
注解
values
方法详细信息
clear(options)
清除表值和格式。
clear(options?: PowerPoint.TableClearOptions): void;
参数
- options
- PowerPoint.TableClearOptions
提供用于清除表的选项。
返回
void
注解
getCellOrNullObject(rowIndex, columnIndex)
获取指定 rowIndex 值处的单元 columnIndex格 和 。
getCellOrNullObject(rowIndex: number, columnIndex: number): PowerPoint.TableCell;
参数
- rowIndex
-
number
单元格的从零开始的行索引。
- columnIndex
-
number
单元格的从零开始的列索引。
返回
指定行和列处的单元格。 如果单元格是合并区域的一部分,而不是合并区域的左上角单元格,则返回属性设置为 isNullObject 的 true 对象。 有关详细信息,请参阅 *OrNullObject 方法和属性。
注解
示例
// 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();
});
getMergedAreas()
获取表示表的合并区域的单元格集合。
getMergedAreas(): PowerPoint.TableCellCollection;
返回
A TableCellCollection 包含表示表格合并区域的单元格。
注解
getShape()
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(options?: PowerPoint.Interfaces.TableLoadOptions): PowerPoint.Table;
参数
为要加载的对象属性提供选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNames?: string | string[]): PowerPoint.Table;
参数
- propertyNames
-
string | string[]
指定要加载的属性的逗号分隔的字符串或字符串数组。
返回
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNamesAndPaths?: {
select?: string;
expand?: string;
}): PowerPoint.Table;
参数
- propertyNamesAndPaths
-
{ select?: string; expand?: string; }
propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。
返回
mergeCells(rowIndex, columnIndex, rowCount, columnCount)
从 rowIndex 和 columnIndex 指定的单元格开始创建一个合并区域。 合并区域跨越指定数量的行数和列数。
mergeCells(rowIndex: number, columnIndex: number, rowCount: number, columnCount: number): void;
参数
- rowIndex
-
number
单元格的从零开始的行索引,以开始合并区域。
- columnIndex
-
number
单元格的从零开始的列索引,以开始合并区域。
- rowCount
-
number
要与起始单元格合并的行数。 必须大于 0。
- columnCount
-
number
要与起始单元格合并的列数。 必须大于 0。
返回
void
注解
toJSON()
覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 PowerPoint.Table 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 PowerPoint.Interfaces.TableData) ,其中包含从原始对象加载的任何子属性的浅层副本。
toJSON(): PowerPoint.Interfaces.TableData;