Office.TableBinding interface

表示两个维度的行和列的绑定,标题可选。

Extends

注解

TableBinding 对象从 Office.Binding 对象继承id属性type、属性getDataAsync、方法和setDataAsync方法。

对于 Excel,请注意,在建立表绑定后,用户添加到表中的每一个新行都会自动包含在绑定中,并且 rowCount 将增加。

属性

columnCount

以整数值的形式获取 TableBinding 中的列数。

hasHeaders

如果表具有标头,则为 True;否则为 false。

rowCount

获取 TableBinding 中的行数,作为整数值。

方法

addColumnsAsync(tableData, options, callback)

将指定的数据作为其他列添加到表中。

addColumnsAsync(tableData, callback)

将指定的数据作为其他列添加到表中。

addRowsAsync(rows, options, callback)

将指定的数据作为其他行添加到表中。

addRowsAsync(rows, callback)

将指定的数据作为其他行添加到表中。

clearFormatsAsync(options, callback)

清除绑定表中的格式。

clearFormatsAsync(callback)

清除绑定表中的格式。

deleteAllDataValuesAsync(options, callback)

删除表中的所有非标题行及其值,并相应地移动 Office 应用程序。

deleteAllDataValuesAsync(callback)

删除表中的所有非标题行及其值,并相应地移动 Office 应用程序。

getFormatsAsync(cellReference, formats, options, callback)

获取表中指定项的格式设置。

getFormatsAsync(cellReference, formats, callback)

获取表中指定项的格式设置。

setFormatsAsync(cellFormat, options, callback)

设置表中指定项和数据的格式设置。

setFormatsAsync(cellFormat, callback)

设置表中指定项和数据的格式设置。

setTableOptionsAsync(tableOptions, options, callback)

更新绑定表上的表格式选项。

setTableOptionsAsync(tableOptions, callback)

更新绑定表上的表格式选项。

属性详细信息

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 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 版的其他说明:在对此方法的单个调用中,传递给数据参数的 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 版的其他说明:在对此方法的单个调用中,传递给数据参数的 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 版的其他说明:在对此方法的单个调用中,传递给数据参数的 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 版的其他说明:在对此方法的单个调用中,传递给数据参数的 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.AsyncResultvalue结果的 属性是一个数组,其中包含一个或多个 JavaScript 对象,这些对象指定其相应单元格的格式。

返回

void

注解

返回的格式结构

返回值数组中的每个 JavaScript 对象都有以下形式: {cells:{ cell_range }, format:{ format_definition }}

属性 cells: 使用以下值之一指定要设置格式的区域。

单元格属性中支持的范围

cells 范围设置 说明
{row: n} 指定表中从零开始的第 n 行数据的范围。
{column: n} 指定表中从零开始的第 n 列数据的范围。
{row: i, column: j} 指定单个单元格,该单元格是表的 ith 行和 jth 列。
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.AsyncResultvalue结果的 属性是一个数组,其中包含一个或多个 JavaScript 对象,这些对象指定其相应单元格的格式。

返回

void

注解

返回的格式结构

返回值数组中的每个 JavaScript 对象都有以下形式: {cells:{ cell_range }, format:{ format_definition }}

属性 cells: 使用以下值之一指定要设置格式的区域。

单元格属性中支持的范围

cells 范围设置 说明
{row: n} 指定表中从零开始的第 n 行数据的范围。
{column: n} 指定表中从零开始的第 n 列数据的范围。
{row: i, column: j} 指定单个单元格,该单元格是表的 ith 行和 jth 列。
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} 指定单个单元格,该单元格是表的 ith 行和 jth 列。
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: 指定数字格式“代码”字符串来指定数字格式。 你可以指定的数字格式字符串对应于你可以使用“设置单元格格式”对话框“数字”选项卡上的“自定义”类别在 Excel 中设置的字符串。 此示例演示如何将数字格式设置为带两个小数位的百分数形式:

format: {numberFormat:"0.00%"}

有关详细信息,请参阅如何Create自定义数字格式

若要在写入数据时设置表的格式设置,请使用 或 TableBinding.setDataAsync 方法的 Document.setSelectedDataAsync tableOptions 和 cellFormat 可选参数。

使用 和 TableBinding.setDataAsync 方法的Document.setSelectedDataAsync可选参数设置格式仅适用于首次写入数据时设置格式。 若要在写入数据后更改格式,请使用以下方法。

  • 若要更新单元格格式(如字体颜色和样式),请使用 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} 指定单个单元格,该单元格是表的 ith 行和 jth 列。
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: 指定数字格式“代码”字符串来指定数字格式。 你可以指定的数字格式字符串对应于你可以使用“设置单元格格式”对话框“数字”选项卡上的“自定义”类别在 Excel 中设置的字符串。 此示例演示如何将数字格式设置为带两个小数位的百分数形式:

format: {numberFormat:"0.00%"}

有关详细信息,请参阅如何Create自定义数字格式

若要在写入数据时设置表的格式设置,请使用 或 TableBinding.setDataAsync 方法的 Document.setSelectedDataAsync tableOptions 和 cellFormat 可选参数。

使用 和 TableBinding.setDataAsync 方法的Document.setSelectedDataAsync可选参数设置格式仅适用于首次写入数据时设置格式。 若要在写入数据后更改格式,请使用以下方法。

  • 若要更新单元格格式(如字体颜色和样式),请使用 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 对象中返回的任何类型的项,而不进行更改。