Office.Binding interface

ドキュメントのセクションに対するバインドを表します。

Binding オブジェクトは、型に関係なくすべてのバインドが所有する機能を公開します。

Binding オブジェクトが直接呼び出されることはありません。 これは、各種類のバインディング ( Office.MatrixBindingOffice.TableBinding、または Office.TextBinding を表すオブジェクトの抽象的な親クラスです。 これら 3 つのオブジェクトはすべて、バインド内のデータを操作することを可能にする Binding オブジェクトの getDataAsync メソッドと setDataAsync メソッドを継承します。 また、これらのプロパティ値を照会するための ID プロパティと型プロパティも継承します。 さらに、MatrixBinding および TableBinding オブジェクトは、行数と列数をカウントする機能など、マトリックスおよびテーブル固有の機能も公開します。

プロパティ

document

バインドに関連付けられている Document オブジェクトを取得します。

id

同じ Office.Document オブジェクト内のバインド間でこのバインドを一意に識別する文字列。

type

バインドの種類を取得します。

メソッド

addHandlerAsync(eventType, handler, options, callback)

指定した Office.EventType のオブジェクトにイベント ハンドラーを追加します。 サポートされている EventTypes は Office.EventType.BindingDataChangedOffice.EventType.BindingSelectionChanged です。

addHandlerAsync(eventType, handler, callback)

指定した Office.EventType のオブジェクトにイベント ハンドラーを追加します。 サポートされている EventTypes は Office.EventType.BindingDataChangedOffice.EventType.BindingSelectionChanged です。

getDataAsync(options, callback)

バインド内に含まれるデータを返します。

getDataAsync(callback)

バインド内に含まれるデータを返します。

removeHandlerAsync(eventType, options, callback)

指定されたイベントの種類のバインドから、指定されたハンドラーを削除します。

removeHandlerAsync(eventType, callback)

指定されたイベントの種類のバインドから、指定されたハンドラーを削除します。

setDataAsync(data, options, callback)

指定されたバインド オブジェクトで表されるドキュメントのバインド セクションにデータを書き込みます。

setDataAsync(data, callback)

指定されたバインド オブジェクトで表されるドキュメントのバインド セクションにデータを書き込みます。

プロパティの詳細

document

バインドに関連付けられている Document オブジェクトを取得します。

document: Office.Document;

プロパティ値

Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
    write(asyncResult.value.document.url);
});

// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

id

同じ Office.Document オブジェクト内のバインド間でこのバインドを一意に識別する文字列。

id: string;

プロパティ値

string

Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
    write(asyncResult.value.id);
});

// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

type

バインドの種類を取得します。

type: Office.BindingType;

プロパティ値

Office.context.document.bindings.getByIdAsync("MyBinding", function (asyncResult) { 
    write(asyncResult.value.type); 
}) 

// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

メソッドの詳細

addHandlerAsync(eventType, handler, options, callback)

指定した Office.EventType のオブジェクトにイベント ハンドラーを追加します。 サポートされている EventTypes は Office.EventType.BindingDataChangedOffice.EventType.BindingSelectionChanged です。

addHandlerAsync(eventType: Office.EventType, handler: any, options?: Office.AsyncContextOptions, callback?: (result: Office.AsyncResult<void>) => void): void;

パラメーター

eventType
Office.EventType

イベントの種類。 バインドの場合は、 Office.EventType.BindingDataChanged または Office.EventType.BindingSelectionChanged にすることができます。

handler

any

追加するイベント ハンドラー関数。その唯一のパラメーターが Office.BindingDataChangedEventArgs 型または Office.BindingSelectionChangedEventArgs 型です。

options
Office.AsyncContextOptions

コールバックで使用するために、任意の種類のコンテキスト データを変更されないまま保持するためのオプションを提供します。

callback

(result: Office.AsyncResult<void>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。

返品

void

注釈

要件セット: BindingEvents

各イベント ハンドラー関数の名前が一意である限り、指定した eventType に複数のイベント ハンドラーを追加できます。

addHandlerAsync(eventType, handler, callback)

指定した Office.EventType のオブジェクトにイベント ハンドラーを追加します。 サポートされている EventTypes は Office.EventType.BindingDataChangedOffice.EventType.BindingSelectionChanged です。

addHandlerAsync(eventType: Office.EventType, handler: any, callback?: (result: Office.AsyncResult<void>) => void): void;

パラメーター

eventType
Office.EventType

イベントの種類。 バインドの場合は、 Office.EventType.BindingDataChanged または Office.EventType.BindingSelectionChanged にすることができます。

handler

any

追加するイベント ハンドラー関数。その唯一のパラメーターが Office.BindingDataChangedEventArgs 型または Office.BindingSelectionChangedEventArgs 型です。

callback

(result: Office.AsyncResult<void>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。

返品

void

注釈

要件セット: BindingEvents

各イベント ハンドラー関数の名前が一意である限り、指定した eventType に複数のイベント ハンドラーを追加できます。

// The following code sample calls the select function of the Office object to access the binding
// with ID "MyBinding", and then calls the addHandlerAsync method to add a handler function 
// for the bindingDataChanged event of that binding.
function addEventHandlerToBinding() {
    Office.select("bindings#MyBinding").addHandlerAsync(
        Office.EventType.BindingDataChanged, onBindingDataChanged);
}

function onBindingDataChanged(eventArgs) {
    write("Data has changed in binding: " + eventArgs.binding.id);
}

// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}
// To add an event handler for the BindingSelectionChanged event of a binding, 
// use the addHandlerAsync method of the Binding object.
// The event handler receives an argument of type BindingSelectionChangedEventArgs.
function addEventHandlerToBinding() {
    Office.select("bindings#MyBinding").addHandlerAsync(
        Office.EventType.BindingSelectionChanged, onBindingSelectionChanged);
}

function onBindingSelectionChanged(eventArgs) {
    write(eventArgs.binding.id + " has been selected.");
}
// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

getDataAsync(options, callback)

バインド内に含まれるデータを返します。

getDataAsync<T>(options?: GetBindingDataOptions, callback?: (result: AsyncResult<T>) => void): void;

パラメーター

options
Office.GetBindingDataOptions

バインド内のデータを取得する方法のオプションを指定します。

callback

(result: Office.AsyncResult<T>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。 結果の value プロパティは、指定されたバインドの値です。 coercionType パラメーターが指定された (かつ呼び出しが成功した) 場合、データは CoercionType 列挙トピックで説明されている形式で返されます。

返品

void

注釈

要件セット:

MatrixBinding または TableBinding から呼び出された場合、getDataAsync メソッドは、省略可能な startRow、startColumn、rowCount、および columnCount パラメーターが指定されていれば (連続した有効な範囲が指定されている場合)、バインドされた値のサブセットを返します。

getDataAsync(callback)

バインド内に含まれるデータを返します。

getDataAsync<T>(callback?: (result: AsyncResult<T>) => void): void;

パラメーター

callback

(result: Office.AsyncResult<T>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。 結果の value プロパティは、指定されたバインドの値です。 coercionType パラメーターが指定された (かつ呼び出しが成功した) 場合、データは CoercionType 列挙トピックで説明されている形式で返されます。

返品

void

注釈

要件セット:

MatrixBinding または TableBinding から呼び出された場合、getDataAsync メソッドは、省略可能な startRow、startColumn、rowCount、および columnCount パラメーターが指定されていれば (連続した有効な範囲が指定されている場合)、バインドされた値のサブセットを返します。

function showBindingData() {
    Office.select("bindings#MyBinding").getDataAsync(function (asyncResult) {
        write(asyncResult.value)
    });
}

// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

// There is an important difference in behavior between using the "table" and "matrix" coercionType with the
// Binding.getDataAsync method, with respect to data formatted with header rows, as shown in the following
// two examples. These code examples show event handler functions for the Binding.SelectionChanged event.

// If you specify the "table" coercionType, the TableData.rows property ( result.value.rows in the following
// code example) returns an array that contains only the body rows of the table. So, its 0th row will be the
// first non-header row in the table.
function selectionChanged(evtArgs) { 
    Office.select("bindings#TableTranslate").getDataAsync(
        { coercionType: 'table', 
          startRow: evtArgs.startRow, 
          startCol: 0, 
          rowCount: 1, 
          columnCount: 1 },  
        function (result) { 
            if (result.status === Office.AsyncResultStatus.Succeeded) {
                write("Image to find: " + result.value.rows[0][0]); 
            } 
            else {
                write(result.error.message);
            }
    }); 
}
// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

// However, if you specify the "matrix" coercionType, result.value in the following code example returns an array
// that contains the table header in the 0th row. If the table header contains multiple rows, then these are all
// included in the result.value matrix as separate rows before the table body rows are included.
function selectionChanged(evtArgs) { 
    Office.select("bindings#TableTranslate").getDataAsync(
        { coercionType: 'matrix', 
          startRow: evtArgs.startRow, 
          startCol: 0, 
          rowCount: 1, 
          columnCount: 1 },  
        function (result) { 
            if (result.status === Office.AsyncResultStatus.Succeeded) {
                write("Image to find: " + result.value[1][0]); 
            } 
            else {
                write(result.error.message);
            }
    }); 
}
// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

removeHandlerAsync(eventType, options, callback)

指定されたイベントの種類のバインドから、指定されたハンドラーを削除します。

removeHandlerAsync(eventType: Office.EventType, options?: RemoveHandlerOptions, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

eventType
Office.EventType

イベントの種類。 バインドの場合は、 Office.EventType.BindingDataChanged または Office.EventType.BindingSelectionChanged にすることができます。

options
Office.RemoveHandlerOptions

削除されるイベント ハンドラーを決定するオプションを提供します。

callback

(result: Office.AsyncResult<void>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。

返品

void

注釈

要件セット: BindingEvents

removeHandlerAsync(eventType, callback)

指定されたイベントの種類のバインドから、指定されたハンドラーを削除します。

removeHandlerAsync(eventType: Office.EventType, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

eventType
Office.EventType

イベントの種類。 バインドの場合は、 Office.EventType.BindingDataChanged または Office.EventType.BindingSelectionChanged にすることができます。

callback

(result: Office.AsyncResult<void>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。

返品

void

注釈

要件セット: BindingEvents

function removeEventHandlerFromBinding() {
    Office.select("bindings#MyBinding").removeHandlerAsync(
        Office.EventType.BindingDataChanged, {handler:onBindingDataChanged});
}

setDataAsync(data, options, callback)

指定されたバインド オブジェクトで表されるドキュメントのバインド セクションにデータを書き込みます。

setDataAsync(data: TableData | any, options?: SetBindingDataOptions, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

data

Office.TableData | any

現在の選択範囲に設定するデータ。 Office アプリケーションごとに使用可能なデータ型:

文字列: Excel on the web と Windows の場合、および Word on the web と Windows のみ

配列の配列: Excel および Word のみ

Office.TableData: Excel および Word のみ

HTML: Web および Windows 上の Word のみ

Office Open XML: Word のみ

options
Office.SetBindingDataOptions

バインド内のデータを設定する方法のオプションを指定します。

callback

(result: Office.AsyncResult<void>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。

返品

void

注釈

要件セット:

データに対して渡される値には、バインドに書き込まれるデータが含まれます。 次の表に示されるように、渡された値の種類により、書き込まれる内容が決まります。

data 書き込まれるデータ
文字列 プレーン テキストまたは文字列に強制できるものはすべて書き込まれます。
配列の配列 ("matrix") Tabular data without headers will be written. たとえば、3 行 2 列のデータを書き込むには、 \[\["R1C1", "R1C2"\], \["R2C1", "R2C2"\], \["R3C1", "R3C2"\]\] という配列を渡します。 3 行の 1 つの列を書き込むには、次のような配列を渡します: \[\["R1C1"\], \["R2C1"\], \["R3C1"\]\]
TableData オブジェクト ヘッダー付きのテーブルが書き込まれます。

また、バインドにデータを書き込むときに、次のアプリケーション固有の処理が適用されます。 Word の場合、指定されたデータは次のようにバインドに書き込まれます。

data 書き込まれるデータ
文字列 指定されたテキストが書き込まれます。
配列の配列 ("行列") または TableData オブジェクト HTML
HTML 指定された HTML が書き込まれます。 書き込む HTML に無効な HTML が含まれている場合も、エラーは発生しません。 HTML はできる限り書き込まれ、無効なデータは省略されます。
Office Open XML ("Open XML") 指定された XML が書き込まれます。

Excel の場合、指定したデータは次のようにバインドに書き込まれます。

data 書き込まれるデータ
文字列 指定されたテキストが最初にバインドされたセルの値として挿入されます。 また、バインドされたセルに追加する有効な数式を指定できます。 たとえば、data を "=SUM(A1:A5)" と設定すると、指定の範囲内の値が集計されます。 ただし、バインドされたセルで数式を設定する場合、その後、バインドされたセルからは追加された数式 (または既存の数式) を読み取ることができません。 連結されたセルで Binding.getDataAsync メソッドを呼び出してデータを読み取ると、メソッドはセルに表示されているデータ (数式の結果) のみを返します。
配列の配列 (「matrix」)、形状が指定されたバインドの形状と完全に一致する場合 The set of rows and columns are written.You can also specify an array of arrays that contain valid formulas to add them to the bound cells. たとえば、データを \[\["=SUM(A1:A5)","=AVERAGE(A1:A5)"\]\] に設定すると、2 つのセルを含むバインドにこれら 2 つの数式が追加されます。 1 つのバインドされたセルに数式を設定するときと同様に、 Binding.getDataAsync メソッドを使用してバインドから追加した数式 (または既存の数式) を読み取ることはできません。バインドされたセルに表示されるデータのみが返されます。
TableData オブジェクトであり、テーブルの形状が連結されたテーブルと一致している The specified set of rows and/or headers are written, if no other data in surrounding cells will be overwritten. **注**: *data* パラメーターに渡す TableData オブジェクトで数式を指定すると、列内の数式が自動的に複製される Excel の "計算列" 機能により、期待した結果が得られない場合があります。 数式を含む *データ* をバインドされたテーブルに書き込む場合にこの問題を回避するには、( TableData オブジェクトではなく) データを配列の配列として指定し、*coercionType* を Microsoft.Office.Matrix または "matrix" として指定してみてください。

Excel on the web の場合:

  • このメソッドの 1 回の呼び出しで、データ パラメーターに渡される値のセルの合計数が 20,000 を超えることはできません。

  • cellFormat パラメーターに渡される書式設定グループの数は 100 を超えることはできません。 1 つの書式設定グループは、指定のセル範囲に適用される書式設定のセットから構成されます。

上記以外の場合は、エラーが返されます。

setDataAsync メソッドは、オプションの startRow および startColumn パラメーターが指定され、有効な範囲が指定されている場合、テーブルまたはマトリックス バインディングのサブセットにデータを書き込みます。

setDataAsync メソッドに渡されたコールバック関数で、AsyncResult オブジェクトのプロパティを使用して次の情報を戻せます。

プロパティ 使用
AsyncResult.value 取得するオブジェクトまたはデータがないため、常に undefined を返します。
AsyncResult.status 操作の成功または失敗を判断します。
AsyncResult.error 操作が失敗した場合、エラーに関する情報を提供する Error オブジェクトにアクセスします。
AsyncResult.asyncContext 変更せずに AsyncResult オブジェクトで返される任意の型の項目を定義します。

setDataAsync(data, callback)

指定されたバインド オブジェクトで表されるドキュメントのバインド セクションにデータを書き込みます。

setDataAsync(data: TableData | any, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

data

Office.TableData | any

現在の選択範囲に設定するデータ。 Office アプリケーションごとに使用可能なデータ型:

文字列: Excel on the web と Windows の場合、および Word on the web と Windows のみ

配列の配列: Excel および Word のみ

TableData : Excel および Word のみ

HTML: Web および Windows 上の Word のみ

Office Open XML: Word のみ

callback

(result: Office.AsyncResult<void>) => void

省略可能。 コールバックが返されたときに呼び出される関数。その唯一のパラメーターは Office.AsyncResult 型です。

返品

void

注釈

要件セット:

データに対して渡される値には、バインドに書き込まれるデータが含まれます。 次の表に示されるように、渡された値の種類により、書き込まれる内容が決まります。

data 書き込まれるデータ
文字列 プレーン テキストまたは文字列に強制できるものはすべて書き込まれます。
配列の配列 ("matrix") Tabular data without headers will be written. たとえば、3 行 2 列のデータを書き込むには、 \[\["R1C1", "R1C2"\], \["R2C1", "R2C2"\], \["R3C1", "R3C2"\]\] という配列を渡します。 3 行の 1 つの列を書き込むには、次のような配列を渡します: \[\["R1C1"\], \["R2C1"\], \["R3C1"\]\]
TableData オブジェクト ヘッダー付きのテーブルが書き込まれます。

また、バインドにデータを書き込むときに、次のアプリケーション固有の処理が適用されます。 Word の場合、指定されたデータは次のようにバインドに書き込まれます。

data 書き込まれるデータ
文字列 指定されたテキストが書き込まれます。
配列の配列 ("行列") または TableData オブジェクト HTML
HTML 指定された HTML が書き込まれます。 書き込む HTML に無効な HTML が含まれている場合も、エラーは発生しません。 HTML はできる限り書き込まれ、無効なデータは省略されます。
Office Open XML ("Open XML") 指定された XML が書き込まれます。

Excel の場合、指定したデータは次のようにバインドに書き込まれます。

data 書き込まれるデータ
文字列 指定されたテキストが最初にバインドされたセルの値として挿入されます。 また、バインドされたセルに追加する有効な数式を指定できます。 たとえば、data を "=SUM(A1:A5)" と設定すると、指定の範囲内の値が集計されます。 ただし、バインドされたセルで数式を設定する場合、その後、バインドされたセルからは追加された数式 (または既存の数式) を読み取ることができません。 連結されたセルで Binding.getDataAsync メソッドを呼び出してデータを読み取ると、メソッドはセルに表示されているデータ (数式の結果) のみを返します。
配列の配列 (「matrix」)、形状が指定されたバインドの形状と完全に一致する場合 The set of rows and columns are written.You can also specify an array of arrays that contain valid formulas to add them to the bound cells. たとえば、データを \[\["=SUM(A1:A5)","=AVERAGE(A1:A5)"\]\] に設定すると、2 つのセルを含むバインドにこれら 2 つの数式が追加されます。 1 つのバインドされたセルに数式を設定するときと同様に、 Binding.getDataAsync メソッドを使用してバインドから追加した数式 (または既存の数式) を読み取ることはできません。バインドされたセルに表示されるデータのみが返されます。
TableData オブジェクトであり、テーブルの形状が連結されたテーブルと一致している The specified set of rows and/or headers are written, if no other data in surrounding cells will be overwritten. **注**: *data* パラメーターに渡す TableData オブジェクトで数式を指定すると、列内の数式が自動的に複製される Excel の "計算列" 機能により、期待した結果が得られない場合があります。 数式を含む *データ* をバインドされたテーブルに書き込む場合にこの問題を回避するには、( TableData オブジェクトではなく) データを配列の配列として指定し、*coercionType* を Microsoft.Office.Matrix または "matrix" として指定してみてください。

Excel on the web の場合:

  • このメソッドの 1 回の呼び出しで、データ パラメーターに渡される値のセルの合計数が 20,000 を超えることはできません。

  • cellFormat パラメーターに渡される書式設定グループの数は 100 を超えることはできません。 1 つの書式設定グループは、指定のセル範囲に適用される書式設定のセットから構成されます。

上記以外の場合は、エラーが返されます。

setDataAsync メソッドは、オプションの startRow および startColumn パラメーターが指定され、有効な範囲が指定されている場合、テーブルまたはマトリックス バインディングのサブセットにデータを書き込みます。

setDataAsync メソッドに渡されたコールバック関数で、AsyncResult オブジェクトのプロパティを使用して次の情報を戻せます。

プロパティ 使用
AsyncResult.value 取得するオブジェクトまたはデータがないため、常に undefined を返します。
AsyncResult.status 操作の成功または失敗を判断します。
AsyncResult.error 操作が失敗した場合、エラーに関する情報を提供する Error オブジェクトにアクセスします。
AsyncResult.asyncContext 変更せずに AsyncResult オブジェクトで返される任意の型の項目を定義します。

function setBindingData() {
    Office.select("bindings#MyBinding").setDataAsync('Hello World!', function (asyncResult) { });
}

// Specifying the optional coercionType parameter lets you specify the kind of data you want to write to a binding.
// For example, in Word if you want to write HTML to a text binding, you can specify the coercionType parameter 
// as "html" as shown in the following example, which uses HTML <b> tags to make "Hello" bold.
function writeHtmlData() {
    Office.select("bindings#myBinding").setDataAsync(
        "<b>Hello</b> World!", {coercionType: "html"}, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            write('Error: ' + asyncResult.error.message);
        }
    });
}

// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

// In this example, the call to setDataAsync passes the data parameter as an array of arrays
// (to create a single column of three rows), and specifies the data structure with the 
// coercionType parameter as a "matrix".
function writeBoundDataMatrix() {
    Office.select("bindings#myBinding").setDataAsync(
        [['Berlin'],['Munich'],['Duisburg']],{ coercionType: "matrix" }, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
            write('Error: ' + asyncResult.error.message);
        } else {
            write('Bound data: ' + asyncResult.value);
        }
    });
}
// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

// In the writeBoundDataTable function in this example, the call to setDataAsync passes the data parameter 
// as a TableData object (to write three columns and three rows), and specifies the data structure
// with the coercionType parameter as a "table".

// In the updateTableData function, the call to setDataAsync again passes the data parameter as a TableData object,
// but as a single column with a new header and three rows, to update the values in the last column 
// of the table created with the writeBoundDataTable function. The optional zero-based startColumn parameter 
// is specified as 2 to replace the values in the third column of the table.
function writeBoundDataTable() {
    // Create a TableData object.
    const myTable = new Office.TableData();
    myTable.headers = ['First Name', 'Last Name', 'Grade'];
    myTable.rows = [['Kim', 'Abercrombie', 'A'], ['Junmin','Hao', 'C'],['Toni','Poe','B']];

    // Set myTable in the binding.
    Office.select("bindings#myBinding").setDataAsync(myTable, { coercionType: "table" }, 
        function (asyncResult) {
            if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                write('Error: '+ asyncResult.error.message);
        } else {
            write('Bound data: ' + asyncResult.value);
        }
    });
}

// Replace last column with different data.
function updateTableData() {
    const newTable = new Office.TableData();
    newTable.headers = ["Gender"];
    newTable.rows = [["M"],["M"],["F"]];
    Office.select("bindings#myBinding").setDataAsync(newTable, { coercionType: "table", startColumn:2 }, 
        function (asyncResult) {
            if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                write('Error: '+ asyncResult.error.message);
        } else {
            write('Bound data: ' + asyncResult.value);
        }
    });
}

// In this example, the following call passes two formatting groups to cellFormat.
Office.select("bindings#myBinding").setDataAsync([['Berlin'],['Munich'],['Duisburg']],
  {cellFormat:[{cells: {row: 1}, format: {fontColor: "yellow"}}, 
      {cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}]}, 
  function (asyncResult){});