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

// 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 === Office.AsyncResultStatus.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 === Office.AsyncResultStatus.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

注釈

MatrixBindings, TableBindings, TextBindings

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

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

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

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

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

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

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;
}