Office.TableBinding interface
表示两个维度的行和列的绑定,标题可选。
注解
TableBinding 对象从 Office.Binding 对象继承id属性、type属性、getDataAsync方法和setDataAsync方法。
对于 Excel,请注意,建立表绑定后,用户添加到表中的每一行都自动包含在绑定中,并且 rowCount 将增加。
属性
| column |
获取 TableBinding 中的列数,作为整数值。 |
| has |
如果表具有标题,则为 True;否则为 false。 |
| row |
获取 TableBinding 中的行数,作为整数值。 |
方法
| add |
将指定数据作为附加列添加到表中。 |
| add |
将指定数据作为附加列添加到表中。 |
| add |
将指定数据作为附加行添加到表中。 |
| add |
将指定数据作为附加行添加到表中。 |
| clear |
清除绑定表中的格式。 |
| clear |
清除绑定表中的格式。 |
| delete |
删除表中的所有非标题行及其值,并针对 Office 应用程序进行适当移动。 |
| delete |
删除表中的所有非标题行及其值,并针对 Office 应用程序进行适当移动。 |
| get |
获取表中指定项的格式。 |
| get |
获取表中指定项的格式。 |
| set |
设置表中指定项和数据的格式。 |
| set |
设置表中指定项和数据的格式。 |
| set |
更新绑定表上的表格式选项。 |
| set |
更新绑定表上的表格式选项。 |
属性详细信息
columnCount
获取 TableBinding 中的列数,作为整数值。
columnCount: number;
属性值
number
示例
function showBindingColumnCount() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
write("Column: " + asyncResult.value.columnCount);
});
}
// Function that writes to a div with id='message' on the page.
function write(message) {
document.getElementById('message').innerText += message;
}
hasHeaders
如果表具有标题,则为 True;否则为 false。
hasHeaders: boolean;
属性值
boolean
示例
function showBindingHasHeaders() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
write("Binding has headers: " + asyncResult.value.hasHeaders);
});
}
// Function that writes to a div with id='message' on the page.
function write(message) {
document.getElementById('message').innerText += message;
}
rowCount
获取 TableBinding 中的行数,作为整数值。
rowCount: number;
属性值
number
注解
如果通过在桌面版 Excel 中选择单行插入空表,并在“插入”选项卡) 上使用“表格”Excel web 版 (时,这两个 Office 应用程序都会创建一行标题,后跟一个空白行。 但是,如果加载项的脚本为此新插入的表 (创建绑定(例如,使用 Office.Bindings.addFromSelectionAsync 方法) ,然后检查 rowCount 属性的值,则返回的值将根据电子表格是在桌面版 Excel 中还是在 Excel web 版 中打开而有所不同。
在桌面 (上的 Excel(即 Windows 和 Mac) )中,rowCount 将返回 0, (标题后面的空白行不计算在) 。
在 Excel web 版 中,rowCount 将返回 1, (标题后的空白行被计数为) 。
可通过检查是否存在 rowCount == 1 在脚本中解决返回值不同的问题,如果存在,再检查行是否包含所有空字符串。
示例
function showBindingRowCount() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
write("Rows: " + asyncResult.value.rowCount);
});
}
// Function that writes to a div with id='message' on the page.
function write(message) {
document.getElementById('message').innerText += message;
}
方法详细信息
addColumnsAsync(tableData, options, callback)
将指定数据作为附加列添加到表中。
addColumnsAsync(tableData: TableData | any[][], options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;
参数
- tableData
-
Office.TableData | any[][]
数组数组 (“matrix”) 或包含要添加到表中的一列或多列数据的 TableData 对象。 必填。
- options
- Office.AsyncContextOptions
提供用于保留任何类型的上下文数据(不变)以供回调使用的选项。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
若要添加一个或多个指定数据和标头值的列,请将 TableData 对象作为数据参数传递。 若要添加仅指定数据的一个或多个列,请将数组的数组(“矩阵”)以 data 参数形式传递。
addColumnsAsync 操作的成败是原子操作。 That is, the entire add columns operation must succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will report failure):
作为数据参数传递的数组中的每一行必须与要更新的表具有相同的行数。 如果没有,整个操作都会失败。
数组中的每一行和每一单元格都必须成功地将该行或单元格添加到表的新添加列中。 如果出于任何原因任意行或单元格未能添加成功,则整个操作将失败。
如果将 TableData 对象作为数据参数传递,则标题行数必须与要更新的表的行数匹配。
Excel web 版的其他备注:在对此方法的一次调用中,传递到 data 参数的 TableData 对象中的单元格总数不能超过 20,000 个。
示例
// The following example adds a single column with three rows to a bound table with the id "myTable"
// by passing a TableData object as the data argument of the addColumnsAsync method. To succeed,
// the table being updated must have three rows.
// Add a column to a binding of type table by passing a TableData object.
function addColumns() {
const myTable = new Office.TableData();
myTable.headers = [["Cities"]];
myTable.rows = [["Berlin"], ["Roma"], ["Tokyo"]];
Office.context.document.bindings.getByIdAsync("myTable", function (result) {
result.value.addColumnsAsync(myTable);
});
}
// The following example adds a single column with three rows to a bound table with the id myTable
// by passing an array of arrays ("matrix") as the data argument of the addColumnsAsync method.
// To succeed, the table being updated must have three rows.
// Add a column to a binding of type table by passing an array of arrays.
function addColumns() {
const myTable = [["Berlin"], ["Roma"], ["Tokyo"]];
Office.context.document.bindings.getByIdAsync("myTable", function (result) {
result.value.addColumnsAsync(myTable);
});
}
addColumnsAsync(tableData, callback)
将指定数据作为附加列添加到表中。
addColumnsAsync(tableData: TableData | any[][], callback?: (result: AsyncResult<void>) => void): void;
参数
- tableData
-
Office.TableData | any[][]
数组数组 (“matrix”) 或包含要添加到表中的一列或多列数据的 TableData 对象。 必填。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
若要添加一个或多个指定数据和标头值的列,请将 TableData 对象作为数据参数传递。 若要添加仅指定数据的一个或多个列,请将数组的数组(“矩阵”)以 data 参数形式传递。
addColumnsAsync 操作的成败是原子操作。 That is, the entire add columns operation must succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will report failure):
作为数据参数传递的数组中的每一行必须与要更新的表具有相同的行数。 如果没有,整个操作都会失败。
数组中的每一行和每一单元格都必须成功地将该行或单元格添加到表的新添加列中。 如果出于任何原因任意行或单元格未能添加成功,则整个操作将失败。
如果将 TableData 对象作为数据参数传递,则标题行数必须与要更新的表的行数匹配。
Excel web 版的其他备注:在对此方法的一次调用中,传递到 data 参数的 TableData 对象中的单元格总数不能超过 20,000 个。
addRowsAsync(rows, options, callback)
将指定数据作为附加行添加到表中。
addRowsAsync(rows: TableData | any[][], options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;
参数
- rows
-
Office.TableData | any[][]
数组数组 (“matrix”) 或包含要添加到表中的一行或多行数据的 TableData 对象。 必填。
- options
- Office.AsyncContextOptions
提供用于保留任何类型的上下文数据(不变)以供回调使用的选项。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
addRowsAsync 操作的成败是原子操作。 That is, the entire add columns operation must succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will report failure):
作为数据参数传递的数组中的每一行必须具有与要更新的表相同的列数。 如果没有,整个操作都会失败。
数组中的每一列和单元格必须成功地将该列或单元格添加到新添加的行的表中。 如果由于任何原因未能设置任何列或单元格,则整个操作将失败。
如果将 TableData 对象作为数据参数传递,则标题行数必须与要更新的表的行数匹配。
Excel web 版的其他备注:在对此方法的一次调用中,传递到 data 参数的 TableData 对象中的单元格总数不能超过 20,000 个。
示例
function addRowsToTable() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
const binding = asyncResult.value;
binding.addRowsAsync([["6", "k"], ["7", "j"]]);
});
}
addRowsAsync(rows, callback)
将指定数据作为附加行添加到表中。
addRowsAsync(rows: TableData | any[][], callback?: (result: AsyncResult<void>) => void): void;
参数
- rows
-
Office.TableData | any[][]
数组数组 (“matrix”) 或包含要添加到表中的一行或多行数据的 TableData 对象。 必填。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
addRowsAsync 操作的成败是原子操作。 That is, the entire add columns operation must succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will report failure):
作为数据参数传递的数组中的每一行必须具有与要更新的表相同的列数。 如果没有,整个操作都会失败。
数组中的每一列和单元格必须成功地将该列或单元格添加到新添加的行的表中。 如果由于任何原因未能设置任何列或单元格,则整个操作将失败。
如果将 TableData 对象作为数据参数传递,则标题行数必须与要更新的表的行数匹配。
Excel web 版的其他备注:在对此方法的一次调用中,传递到 data 参数的 TableData 对象中的单元格总数不能超过 20,000 个。
clearFormatsAsync(options, callback)
清除绑定表中的格式。
clearFormatsAsync(options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;
参数
- options
- Office.AsyncContextOptions
提供用于保留任何类型的上下文数据(不变)以供回调使用的选项。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
有关详细信息,请参阅 在 Excel 加载项中设置表格格式 。
示例
// The following example shows how to clear the formatting of the bound table with an ID of "myBinding":
Office.select("bindings#myBinding").clearFormatsAsync();
clearFormatsAsync(callback)
清除绑定表中的格式。
clearFormatsAsync(callback?: (result: AsyncResult<void>) => void): void;
参数
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
有关详细信息,请参阅 在 Excel 加载项中设置表格格式 。
deleteAllDataValuesAsync(options, callback)
删除表中的所有非标题行及其值,并针对 Office 应用程序进行适当移动。
deleteAllDataValuesAsync(options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;
参数
- options
- Office.AsyncContextOptions
提供用于保留任何类型的上下文数据(不变)以供回调使用的选项。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
在 Excel 中,如果表没有标题行,则此方法将删除表。
示例
function deleteAllRowsFromTable() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
const binding = asyncResult.value;
binding.deleteAllDataValuesAsync();
});
}
deleteAllDataValuesAsync(callback)
删除表中的所有非标题行及其值,并针对 Office 应用程序进行适当移动。
deleteAllDataValuesAsync(callback?: (result: AsyncResult<void>) => void): void;
参数
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
在 Excel 中,如果表没有标题行,则此方法将删除表。
getFormatsAsync(cellReference, formats, options, callback)
获取表中指定项的格式。
getFormatsAsync(cellReference?: any, formats?: any[], options?: Office.AsyncContextOptions, callback?: (result: AsyncResult< Array<{ cells: any, format: any}>>) => void): void;
参数
- cellReference
-
any
包含名称-值对的对象文本,这些名称-值对指定要从中获取格式的单元格范围。
- formats
-
any[]
指定要获取的格式属性的数组。
- options
- Office.AsyncContextOptions
提供用于保留任何类型的上下文数据(不变)以供回调使用的选项。
- callback
-
(result: Office.AsyncResult< Array<{ cells: any, format: any}>>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
value结果的属性是一个数组,其中包含一个或多个 JavaScript 对象,这些对象指定其相应单元格的格式。
返回
void
注解
返回的格式结构
返回值数组中的每个 JavaScript 对象都具有以下形式: {cells:{ cell_range }, format:{ format_definition }}
该 cells: 属性使用下列值之一指定要设置格式的范围。
单元格属性中支持的范围
cells 范围设置 | 说明 |
|---|---|
{row: n} | 指定表中从零开始的第 n 行数据的范围。 |
{column: n} | 指定表中数据从零开始的第 n 列的范围。 |
{row: i, column: j} | 指定作为表的第 i 行和第 j 列的单个单元格。 |
Office.Table.All | 指定整个表格,包括列标题、数据和总数(如果有)。 |
Office.Table.Data | 仅指定表中的数据(不含标题和总数)。 |
Office.Table.Headers | 仅指定标题行。 |
该 format: 属性指定与 Excel 中“设置单元格格式”对话框中可用的设置子集对应的值 (打开上下文菜单 (右键单击或选择并按住) 然后选择“ 设置单元格格式”或“ 主页>设置单元>格格式) ”。
getFormatsAsync(cellReference, formats, callback)
获取表中指定项的格式。
getFormatsAsync(cellReference?: any, formats?: any[], callback?: (result: AsyncResult< Array<{ cells: any, format: any}>>) => void): void;
参数
- cellReference
-
any
包含名称-值对的对象文本,这些名称-值对指定要从中获取格式的单元格范围。
- formats
-
any[]
指定要获取的格式属性的数组。
- callback
-
(result: Office.AsyncResult< Array<{ cells: any, format: any}>>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
value结果的属性是一个数组,其中包含一个或多个 JavaScript 对象,这些对象指定其相应单元格的格式。
返回
void
注解
返回的格式结构
返回值数组中的每个 JavaScript 对象都具有以下形式: {cells:{ cell_range }, format:{ format_definition }}
该 cells: 属性使用下列值之一指定要设置格式的范围。
单元格属性中支持的范围
cells 范围设置 | 说明 |
|---|---|
{row: n} | 指定表中从零开始的第 n 行数据的范围。 |
{column: n} | 指定表中数据从零开始的第 n 列的范围。 |
{row: i, column: j} | 指定作为表的第 i 行和第 j 列的单个单元格。 |
Office.Table.All | 指定整个表格,包括列标题、数据和总数(如果有)。 |
Office.Table.Data | 仅指定表中的数据(不含标题和总数)。 |
Office.Table.Headers | 仅指定标题行。 |
该 format: 属性指定与 Excel 中“设置单元格格式”对话框中可用的设置子集对应的值 (打开上下文菜单 (右键单击或选择并按住) 然后选择“ 设置单元格格式”或“ 主页>设置单元>格格式) ”。
setFormatsAsync(cellFormat, options, callback)
设置表中指定项和数据的格式。
setFormatsAsync(cellFormat: any[], options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;
参数
- cellFormat
-
any[]
包含指定针对哪些单元格以及适用格式的一个或多个 JavaScript 对象的数组。
- options
- Office.AsyncContextOptions
提供用于保留任何类型的上下文数据(不变)以供回调使用的选项。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
指定 cellFormat 参数
使用 cellFormat 参数设置或更改单元格格式值,如宽度、高度、字体、背景、对齐方式等。 作为 cellFormat 参数传递的值是一个数组,其中包含一个或多个 JavaScript 对象的列表,这些对象指定要 () cells: 目标单元格以及 () format: 应用于这些单元格的格式。
cellFormat 数组中的每个 JavaScript 对象都具有以下形式: {cells:{ cell_range }, format:{ format_definition }}
该 cells: 属性使用下列值之一指定要设置格式的范围。
单元格属性中支持的范围
cells 范围设置 | 说明 |
|---|---|
{row: n} | 指定表中从零开始的第 n 行数据的范围。 |
{column: n} | 指定表中数据从零开始的第 n 列的范围。 |
{row: i, column: j} | 指定作为表的第 i 行和第 j 列的单个单元格。 |
Office.Table.All | 指定整个表格,包括列标题、数据和总数(如果有)。 |
Office.Table.Data | 仅指定表中的数据(不含标题和总数)。 |
Office.Table.Headers | 仅指定标题行。 |
该 format: 属性指定与 Excel 中“设置单元格格式”对话框中可用的设置子集对应的值 (打开上下文菜单 (右键单击或选择并按住) 然后选择“ 设置单元格格式”或“ 主页>设置单元>格格式) ”。
将属性的 format: 值指定为一个或多个属性名称的列表 - JavaScript 对象文本中的值对。 属性名称指定要设置的格式属性的名称,值则指定属性值。 您可以为给定的格式指定多个值,如字体的颜色及大小。
下面是三个 format: 属性值示例:
//Set cells: font color to green and size to 15 points.
format: {fontColor : "green", fontSize : 15}
//Set cells: border to dotted blue.
format: {borderStyle: "dotted", borderColor: "blue"}
//Set cells: background to red and alignment to centered.
format: {backgroundColor: "red", alignHorizontal: "center"}
可以通过在属性中 numberFormat: 指定数字格式“code”字符串来指定数字格式。 你可以指定的数字格式字符串对应于你可以使用“设置单元格格式”对话框“数字”选项卡上的“自定义”类别在 Excel 中设置的字符串。 此示例演示如何将数字格式设置为带两个小数位的百分数形式:
format: {numberFormat:"0.00%"}
有关详细信息,请参阅如何 创建自定义数字格式。
若要在写入数据时设置表的格式,请使用 OR TableBinding.setDataAsync 方法的 Document.setSelectedDataAsync tableOptions 和 cellFormat 可选参数。
使用 and Document.setSelectedDataAsyncTableBinding.setDataAsync 方法的可选参数设置格式仅适用于在首次写入数据时设置格式。 若要在写入数据后更改格式,请使用以下方法。
若要更新单元格格式(如字体颜色和样式),请使用此
TableBinding.setFormatsAsync方法) (方法。要更新表选项(如带状行和筛选器按钮),请使用该
TableBinding.setTableOptions方法。若要清除格式,请使用该
TableBinding.clearFormats方法。
有关更多详细信息和示例,请参阅如何在 Excel 加载项中设置表格格式。
示例
// Specifying a single target
// The following example shows a cellFormat value that sets the font color of the header row to red.
Office.select("bindings#myBinding").setFormatsAsync(
[{cells: Office.Table.Headers, format: {fontColor: "red"}}],
function (asyncResult){});
// Specifying multiple targets
// The setFormatsAsync method can support formatting multiple targets within the bound table in a
// single function call. To do that, you pass a list of objects in the cellFormat array
// for each target that you want to format.
// For example, the following line of code will set the font color of the first row yellow,
// and the fourth cell in the third row to have a white border and bold text.
Office.select("bindings#myBinding").setFormatsAsync(
[{cells: {row: 1}, format: {fontColor: "yellow"}},
{cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}],
function (asyncResult){});
// Additional remarks for Excel Online
// The number of formatting groups passed to the cellFormat parameter can't exceed 100.
// A single formatting group consists of a set of formatting applied to a specified range of cells.
// For example, the following call passes two formatting groups to cellFormat.
Office.select("bindings#myBinding").setFormatsAsync(
[{cells: {row: 1}, format: {fontColor: "yellow"}},
{cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}],
function (asyncResult){});
setFormatsAsync(cellFormat, callback)
设置表中指定项和数据的格式。
setFormatsAsync(cellFormat: any[], callback?: (result: AsyncResult<void>) => void): void;
参数
- cellFormat
-
any[]
包含指定针对哪些单元格以及适用格式的一个或多个 JavaScript 对象的数组。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
指定 cellFormat 参数
使用 cellFormat 参数设置或更改单元格格式值,如宽度、高度、字体、背景、对齐方式等。 作为 cellFormat 参数传递的值是一个数组,其中包含一个或多个 JavaScript 对象的列表,这些对象指定要 () cells: 目标单元格以及 () format: 应用于这些单元格的格式。
cellFormat 数组中的每个 JavaScript 对象都具有以下形式: {cells:{ cell_range }, format:{ format_definition }}
该 cells: 属性使用下列值之一指定要设置格式的范围。
单元格属性中支持的范围
cells 范围设置 | 说明 |
|---|---|
{row: n} | 指定表中从零开始的第 n 行数据的范围。 |
{column: n} | 指定表中数据从零开始的第 n 列的范围。 |
{row: i, column: j} | 指定作为表的第 i 行和第 j 列的单个单元格。 |
Office.Table.All | 指定整个表格,包括列标题、数据和总数(如果有)。 |
Office.Table.Data | 仅指定表中的数据(不含标题和总数)。 |
Office.Table.Headers | 仅指定标题行。 |
该 format: 属性指定与 Excel 中“设置单元格格式”对话框中可用的设置子集对应的值 (打开上下文菜单 (右键单击或选择并按住) 然后选择“ 设置单元格格式”或“ 主页>设置单元>格格式) ”。
将属性的 format: 值指定为一个或多个属性名称的列表 - JavaScript 对象文本中的值对。 属性名称指定要设置的格式属性的名称,值则指定属性值。 您可以为给定的格式指定多个值,如字体的颜色及大小。
下面是三个 format: 属性值示例:
//Set cells: font color to green and size to 15 points.
format: {fontColor : "green", fontSize : 15}
//Set cells: border to dotted blue.
format: {borderStyle: "dotted", borderColor: "blue"}
//Set cells: background to red and alignment to centered.
format: {backgroundColor: "red", alignHorizontal: "center"}
可以通过在属性中 numberFormat: 指定数字格式“code”字符串来指定数字格式。 你可以指定的数字格式字符串对应于你可以使用“设置单元格格式”对话框“数字”选项卡上的“自定义”类别在 Excel 中设置的字符串。 此示例演示如何将数字格式设置为带两个小数位的百分数形式:
format: {numberFormat:"0.00%"}
有关详细信息,请参阅如何 创建自定义数字格式。
若要在写入数据时设置表的格式,请使用 OR TableBinding.setDataAsync 方法的 Document.setSelectedDataAsync tableOptions 和 cellFormat 可选参数。
使用 and Document.setSelectedDataAsyncTableBinding.setDataAsync 方法的可选参数设置格式仅适用于在首次写入数据时设置格式。 若要在写入数据后更改格式,请使用以下方法。
若要更新单元格格式(如字体颜色和样式),请使用此
TableBinding.setFormatsAsync方法) (方法。要更新表选项(如带状行和筛选器按钮),请使用该
TableBinding.setTableOptions方法。若要清除格式,请使用该
TableBinding.clearFormats方法。
有关更多详细信息和示例,请参阅如何在 Excel 加载项中设置表格格式。
setTableOptionsAsync(tableOptions, options, callback)
更新绑定表上的表格式选项。
setTableOptionsAsync(tableOptions: any, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;
参数
- tableOptions
-
any
包含定义要应用的表选项的属性名称 - 值对列表的对象文字。
- options
- Office.AsyncContextOptions
提供用于保留任何类型的上下文数据(不变)以供回调使用的选项。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
要求集: 不在集合中
在传递给 goToByIdAsync 方法的回调函数中,您可以使用 AsyncResult 对象的属性返回以下信息。
| 属性 | 用途 |
|---|---|
AsyncResult.value | 始终返回 undefined ,因为设置格式时没有要检索的数据或对象。 |
AsyncResult.status | 确定操作是成功还是失败。 |
AsyncResult.error | 如果操作失败,则访问提供错误信息的 Error 对象。 |
AsyncResult.asyncContext | 定义在 AsyncResult 对象中返回且不进行更改的任何类型的项。 |
示例
// The following example shows how to:
// 1. Create an object literal that specifies the table formatting options to update on the bound table.
// 2. Call setTableOptions on a previously bound table (with an id of myBinding) passing the object
// with formatting setting as the tableOptions parameter.
function updateTableFormatting(){
const tableOptions = {bandedRows: true, filterButton: false, style: "TableStyleMedium3"};
Office.select("bindings#myBinding").setTableOptionsAsync(tableOptions, function(asyncResult){});
}
setTableOptionsAsync(tableOptions, callback)
更新绑定表上的表格式选项。
setTableOptionsAsync(tableOptions: any, callback?: (result: AsyncResult<void>) => void): void;
参数
- tableOptions
-
any
包含定义要应用的表选项的属性名称 - 值对列表的对象文字。
- callback
-
(result: Office.AsyncResult<void>) => void
可选。 回调返回时调用的函数,其唯一参数的类型为 Office.AsyncResult。
返回
void
注解
要求集: 不在集合中
在传递给 goToByIdAsync 方法的回调函数中,您可以使用 AsyncResult 对象的属性返回以下信息。
| 属性 | 用途 |
|---|---|
AsyncResult.value | 始终返回 undefined ,因为设置格式时没有要检索的数据或对象。 |
AsyncResult.status | 确定操作是成功还是失败。 |
AsyncResult.error | 如果操作失败,则访问提供错误信息的 Error 对象。 |
AsyncResult.asyncContext | 定义在 AsyncResult 对象中返回且不进行更改的任何类型的项。 |