Office.Bindings interface

アドイン がドキュメント内に持つバインドを表します。

プロパティ

document

このバインドのセットに関連付けられているドキュメントを表す Office.Document オブジェクトを取得します。

メソッド

addFromNamedItemAsync(itemName, bindingType, options, callback)

ドキュメント内の名前付きオブジェクトに対するバインドを作成します。

addFromNamedItemAsync(itemName, bindingType, callback)

ドキュメント内の名前付きオブジェクトに対するバインドを作成します。

addFromPromptAsync(bindingType, options, callback)

ドキュメントで選択を行うようユーザーに求めることで、バインドを作成します。

addFromPromptAsync(bindingType, callback)

ドキュメントで選択を行うようユーザーに求めることで、バインドを作成します。

addFromSelectionAsync(bindingType, options, callback)

ユーザーの現在の選択に基づいてバインドを作成します。

addFromSelectionAsync(bindingType, callback)

ユーザーの現在の選択に基づいてバインドを作成します。

getAllAsync(options, callback)

以前に作成されたバインドをすべて取得します。

getAllAsync(callback)

以前に作成されたバインドをすべて取得します。

getByIdAsync(id, options, callback)

名前に基づいてバインドを取得します

getByIdAsync(id, callback)

名前に基づいてバインドを取得します

releaseByIdAsync(id, options, callback)

ドキュメントからバインドを削除します

releaseByIdAsync(id, callback)

ドキュメントからバインドを削除します

プロパティの詳細

document

このバインドのセットに関連付けられているドキュメントを表す Office.Document オブジェクトを取得します。

document: Document;

プロパティ値

メソッドの詳細

addFromNamedItemAsync(itemName, bindingType, options, callback)

ドキュメント内の名前付きオブジェクトに対するバインドを作成します。

addFromNamedItemAsync(itemName: string, bindingType: BindingType, options?: AddBindingFromNamedItemOptions, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

itemName

string

ドキュメント内のバインド可能なオブジェクトの名前。 たとえば、Excel の 'MyExpenses' テーブルです。

bindingType
Office.BindingType

データの Office.BindingType 。 選択したオブジェクトを指定した型に強制できない場合、メソッドは null を返します。

options
Office.AddBindingFromNamedItemOptions

作成されるバインドを構成するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、指定した名前付き項目を表す Binding オブジェクトです。

戻り値

void

注釈

要件セット:

Excel の場合、itemName パラメーターは名前付き範囲またはテーブルを参照できます。

既定では、Excel のテーブルを追加すると、最初に追加したテーブルには "Table1"、次に追加したテーブルには "Table2" という名前が割り当てられます。 Excel UI でテーブルにわかりやすい名前を割り当てるには、[テーブル ツール] |の [テーブル名] プロパティを使用します。リボンの [デザイン] タブ。

: Excel では、名前付き項目としてテーブルを指定する場合は、名前を完全に修飾して、ワークシート名を次の形式のテーブルの名前に含める必要があります。"Sheet1!Table1"

Word の場合、itemName パラメーターはリッチ テキスト コンテンツ コントロールの Title プロパティを参照します。 (リッチ テキスト コンテンツ コントロール以外のコンテンツ コントロールにはバインドできません)。

既定では、コンテンツ コントロールには Title 値が割り当てされていません。 Word UI で意味のあるテーブル名を割り当てるには、リボンの [ 開発者] タブの [ コントロール] グループから [ リッチ テキスト] コンテンツ コントロールを挿入した後、[ コントロール] グループの [ プロパティ] コマンドを使用して [ コンテンツ コントロールのプロパティ] ダイアログ ボックスを表示します。 次に、コンテンツ コントロールの [ タイトル] プロパティに、コードから参照する名前を設定します。

: Word では、同じ Title プロパティ値 (名前) を持つ複数のリッチ テキスト コンテンツ コントロールがあり、このメソッドを使用してこれらのコンテンツ コントロールにバインドしようとすると (itemName パラメーターとして名前を指定することで)、操作は失敗します。

// The following example adds a binding to the myRange named item in Excel as a "matrix" binding,
// and assigns the binding's id as myMatrix.
function bindNamedItem() {
    Office.context.document.bindings.addFromNamedItemAsync(
        "myRange", "matrix", {id:'myMatrix'}, function (result) {
        if (result.status == 'succeeded'){
            write('Added new binding with type: ' + result.value.type + ' and id: ' + result.value.id);
            }
        else
            write('Error: ' + result.error.message);
    });
}

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

// The following example adds a binding to the Table1 named item in Excel as a "table" binding,
// and assigns the binding's id as myTable.
function bindNamedItem() {
    Office.context.document.bindings.addFromNamedItemAsync(
        "Table1", "table", {id:'myTable'}, function (result) {
        if (result.status == 'succeeded'){
            write('Added new binding with type: ' + result.value.type + ' and id: ' + result.value.id);
            }
        else
            write('Error: ' + result.error.message);
    });
}

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

// The following example creates a text binding in Word to a rich text content control named "FirstName",
// assigns the id "firstName", and then displays that information.
function bindContentControl() {
    Office.context.document.bindings.addFromNamedItemAsync('FirstName', 
        Office.BindingType.Text, {id:'firstName'},
        function (result) {
            if (result.status === Office.AsyncResultStatus.Succeeded) {
                write('Control bound. Binding.id: '
                    + result.value.id + ' Binding.type: ' + result.value.type);
            } else {
                write('Error:', result.error.message);
            }
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

addFromNamedItemAsync(itemName, bindingType, callback)

ドキュメント内の名前付きオブジェクトに対するバインドを作成します。

addFromNamedItemAsync(itemName: string, bindingType: BindingType, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

itemName

string

ドキュメント内のバインド可能なオブジェクトの名前。 たとえば、Excel の 'MyExpenses' テーブルです。

bindingType
Office.BindingType

データの Office.BindingType 。 選択したオブジェクトを指定した型に強制できない場合、メソッドは null を返します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、指定した名前付き項目を表す Binding オブジェクトです。

戻り値

void

注釈

MatrixBindingsTableBindingsTextBindings

Excel の場合、itemName パラメーターは名前付き範囲またはテーブルを参照できます。

既定では、Excel のテーブルを追加すると、最初に追加したテーブルには "Table1"、次に追加したテーブルには "Table2" という名前が割り当てられます。 Excel UI でテーブルにわかりやすい名前を割り当てるには、[テーブル ツール] |の [テーブル名] プロパティを使用します。リボンの [デザイン] タブ。

: Excel では、名前付き項目としてテーブルを指定する場合は、名前を完全に修飾して、ワークシート名を次の形式のテーブルの名前に含める必要があります。"Sheet1!Table1"

Word の場合、itemName パラメーターはリッチ テキスト コンテンツ コントロールの Title プロパティを参照します。 (リッチ テキスト コンテンツ コントロール以外のコンテンツ コントロールにはバインドできません)。

既定では、コンテンツ コントロールには Title 値が割り当てされていません。 Word UI で意味のあるテーブル名を割り当てるには、リボンの [ 開発者] タブの [ コントロール] グループから [ リッチ テキスト] コンテンツ コントロールを挿入した後、[ コントロール] グループの [ プロパティ] コマンドを使用して [ コンテンツ コントロールのプロパティ] ダイアログ ボックスを表示します。 次に、コンテンツ コントロールの [ タイトル] プロパティに、コードから参照する名前を設定します。

: Word では、同じ Title プロパティ値 (名前) を持つ複数のリッチ テキスト コンテンツ コントロールがあり、このメソッドを使用してこれらのコンテンツ コントロールにバインドしようとすると (itemName パラメーターとして名前を指定することで)、操作は失敗します。

addFromPromptAsync(bindingType, options, callback)

ドキュメントで選択を行うようユーザーに求めることで、バインドを作成します。

addFromPromptAsync(bindingType: BindingType, options?: AddBindingFromPromptOptions, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

bindingType
Office.BindingType

作成するバインド オブジェクトの種類を指定します。 必須です。 選択したオブジェクトを指定した型に強制できない場合は null を返します。

options
Office.AddBindingFromPromptOptions

プロンプトを構成し、作成されるバインドを識別するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、ユーザーによって指定された選択範囲を表す Binding オブジェクトです。

戻り値

void

注釈

要件セット: セットに含まれていない

指定した型のバインド オブジェクトを Bindings コレクションに追加します。これは、指定された ID で識別されます。 指定した選択範囲をバインドできない場合、メソッドは失敗します。

function addBindingFromPrompt() {
    Office.context.document.bindings.addFromPromptAsync(
        Office.BindingType.Text, 
        { id: 'MyBinding', promptText: 'Select text to bind to.' },
        function (asyncResult) {
            write('Added new binding with type: ' + asyncResult.value.type + ' and id: ' + asyncResult.value.id);
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

addFromPromptAsync(bindingType, callback)

ドキュメントで選択を行うようユーザーに求めることで、バインドを作成します。

addFromPromptAsync(bindingType: BindingType, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

bindingType
Office.BindingType

作成するバインド オブジェクトの種類を指定します。 必須です。 選択したオブジェクトを指定した型に強制できない場合は null を返します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、ユーザーによって指定された選択範囲を表す Binding オブジェクトです。

戻り値

void

注釈

要件セット: セットに含まれていない

指定した型のバインド オブジェクトを Bindings コレクションに追加します。これは、指定された ID で識別されます。 指定した選択範囲をバインドできない場合、メソッドは失敗します。

addFromSelectionAsync(bindingType, options, callback)

ユーザーの現在の選択に基づいてバインドを作成します。

addFromSelectionAsync(bindingType: BindingType, options?: AddBindingFromSelectionOptions, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

bindingType
Office.BindingType

作成するバインド オブジェクトの種類を指定します。 必須です。 選択したオブジェクトを指定した型に強制できない場合は null を返します。

options
Office.AddBindingFromSelectionOptions

作成されるバインドを識別するためのオプションを提供します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、ユーザーによって指定された選択範囲を表す Binding オブジェクトです。

戻り値

void

注釈

要件セット:

指定した種類のバインド オブジェクトを Bindings コレクションに追加します。これは、指定された ID で識別されます。

メモ Excel では、既存のバインドの Binding.id を渡す addFromSelectionAsync メソッドを呼び出すと、そのバインドの Binding.type が使用され、bindingType パラメーターに別の値を指定してその型を変更することはできません。 既存の ID を使用して bindingType を変更する必要がある場合は、Bindings.releaseByIdAsync メソッドを最初に呼び出してバインドを解放し、addFromSelectionAsync メソッドを呼び出して新しい型でバインドを再確立します。

function addBindingFromSelection() {
    Office.context.document.bindings.addFromSelectionAsync(Office.BindingType.Text, { id: 'MyBinding' }, 
        function (asyncResult) {
        write('Added new binding with type: ' + asyncResult.value.type + ' and id: ' + asyncResult.value.id);
        }
    );
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

addFromSelectionAsync(bindingType, callback)

ユーザーの現在の選択に基づいてバインドを作成します。

addFromSelectionAsync(bindingType: BindingType, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

bindingType
Office.BindingType

作成するバインド オブジェクトの種類を指定します。 必須です。 選択したオブジェクトを指定した型に強制できない場合は null を返します。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、ユーザーによって指定された選択範囲を表す Binding オブジェクトです。

戻り値

void

注釈

要件セット:

指定した種類のバインド オブジェクトを Bindings コレクションに追加します。これは、指定された ID で識別されます。

メモ Excel では、既存のバインドの Binding.id を渡す addFromSelectionAsync メソッドを呼び出すと、そのバインドの Binding.type が使用され、bindingType パラメーターに別の値を指定してその型を変更することはできません。 既存の ID を使用して bindingType を変更する必要がある場合は、Bindings.releaseByIdAsync メソッドを最初に呼び出してバインドを解放し、addFromSelectionAsync メソッドを呼び出して新しい型でバインドを再確立します。

getAllAsync(options, callback)

以前に作成されたバインドをすべて取得します。

getAllAsync(options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<Binding[]>) => void): void;

パラメーター

options
Office.AsyncContextOptions

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

callback

(result: Office.AsyncResult<Office.Binding[]>) => void

コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、参照される Bindings オブジェクトに対して作成された各バインドを含む配列です。

戻り値

void

注釈

要件セット:

getAllAsync(callback)

以前に作成されたバインドをすべて取得します。

getAllAsync(callback?: (result: AsyncResult<Binding[]>) => void): void;

パラメーター

callback

(result: Office.AsyncResult<Office.Binding[]>) => void

コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、参照される Bindings オブジェクトに対して作成された各バインドを含む配列です。

戻り値

void

注釈

要件セット:

function displayAllBindingNames() {
    Office.context.document.bindings.getAllAsync(function (asyncResult) {
        let bindingString = '';
        for (let i in asyncResult.value) {
            bindingString += asyncResult.value[i].id + '\n';
        }
        write('Existing bindings: ' + bindingString);
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

getByIdAsync(id, options, callback)

名前に基づいてバインドを取得します

getByIdAsync(id: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

id

string

バインド オブジェクトの一意の名前を指定します。 必須です。

options
Office.AsyncContextOptions

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

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、呼び出しの ID で指定された Binding オブジェクトです。

戻り値

void

注釈

要件セット:

指定した ID が存在しない場合、失敗します。

getByIdAsync(id, callback)

名前に基づいてバインドを取得します

getByIdAsync(id: string, callback?: (result: AsyncResult<Binding>) => void): void;

パラメーター

id

string

バインド オブジェクトの一意の名前を指定します。 必須です。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。 結果のプロパティは value 、呼び出しの ID で指定された Binding オブジェクトです。

戻り値

void

注釈

要件セット:

指定した ID が存在しない場合、失敗します。

function displayBindingType() {
    Office.context.document.bindings.getByIdAsync('MyBinding', function (asyncResult) {
        write('Retrieved binding with type: ' + asyncResult.value.type + ' and id: ' + asyncResult.value.id);
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

releaseByIdAsync(id, options, callback)

ドキュメントからバインドを削除します

releaseByIdAsync(id: string, options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

id

string

バインド オブジェクトの一意の識別名を指定します。 必須です。

options
Office.AsyncContextOptions

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

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット:

指定した ID が存在しない場合、失敗します。

releaseByIdAsync(id, callback)

ドキュメントからバインドを削除します

releaseByIdAsync(id: string, callback?: (result: AsyncResult<void>) => void): void;

パラメーター

id

string

バインド オブジェクトの一意の識別名を指定します。 必須です。

callback

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

オプション。 コールバックから戻るときに呼び出される関数。パラメーターは Office.AsyncResult 型のみです。

戻り値

void

注釈

要件セット:

指定した ID が存在しない場合、失敗します。

Office.context.document.bindings.releaseByIdAsync("MyBinding", function (asyncResult) { 
    write("Released MyBinding!"); 
}); 
// Function that writes to a div with id='message' on the page. 
function write(message){ 
    document.getElementById('message').innerText += message;  
}