PowerPoint.BindingCollection class
プレゼンテーションに含まれるすべてのバインド オブジェクトのコレクションを表します。
- Extends
注釈
[ API セット: PowerPointApi 1.8 ]
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
// Loads bindings.
await PowerPoint.run(async (context) => {
const bindings = context.presentation.bindings;
bindings.load("items");
await context.sync();
const bindingCount = bindings.items.length;
if (bindingCount === 0) {
console.log(`There are no bindings.`);
} else if (bindingCount === 1) {
console.log("There's 1 binding.");
} else {
console.log(`There are ${bindingCount} bindings.`);
}
bindings.items.forEach((binding) => {
getShapeForBindingId(binding.id).then((shape) => {
if (shape) {
console.log(`Binding ID: ${binding.id} refers to shape ID ${shape.id}`);
} else {
console.log(`Binding ID: ${binding.id} doesn't refers to shape.`);
}
});
});
populateBindingsDropdown(bindings.items);
});
プロパティ
| context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
| items | このコレクション内に読み込まれた子アイテムを取得します。 |
メソッド
| add(shape, binding |
特定の Shape に新しいバインドを追加します。 指定した ID がバインドによって既に使用されている場合は、既存のバインドが上書きされます。 |
| add(shape, binding |
特定の Shape に新しいバインドを追加します。 指定した ID がバインドによって既に使用されている場合は、既存のバインドが上書きされます。 |
| add |
現在の選択に基づいて新しいバインドを追加します。 選択範囲に複数の領域がある場合は、 |
| add |
現在の選択に基づいて新しいバインドを追加します。 選択範囲に複数の領域がある場合は、 |
| get |
コレクションに含まれるバインドの数を取得します。 |
| get |
ID を使用してバインド オブジェクトを取得します。 その ID とのバインドがない場合は、ItemNotFoundException をスローします。 |
| get |
項目の配列内の位置に基づいて、バインド オブジェクトを取得します。 インデックスが 0 より小さい場合、またはコレクション内の項目の数以上の場合は、InvalidArgumentException をスローします。 |
| get |
ID を使用してバインド オブジェクトを取得します。 バインド オブジェクトが存在しない場合、このメソッドは |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| toJSON() | API オブジェクトが |
プロパティの詳細
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
items
メソッドの詳細
add(shape, bindingType, id)
特定の Shape に新しいバインドを追加します。 指定した ID がバインドによって既に使用されている場合は、既存のバインドが上書きされます。
add(shape: PowerPoint.Shape, bindingType: PowerPoint.BindingType, id: string): PowerPoint.Binding;
パラメーター
- shape
- PowerPoint.Shape
バインドが追加される図形。
- bindingType
- PowerPoint.BindingType
バインドの種類。
BindingType
を参照してください。
- id
-
string
バインドの ID。
戻り値
注釈
[ API セット: PowerPointApi 1.8 ]
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
// Inserts an image with binding.
await PowerPoint.run(async (context) => {
const bindingId = (document.getElementById("temp-binding-id") as HTMLInputElement).value;
const slide = context.presentation.getSelectedSlides().getItemAt(0);
const myShape = slide.shapes.addGeometricShape(PowerPoint.GeometricShapeType.rectangle, {
top: 100,
left: 30,
width: 200,
height: 200
});
myShape.fill.setImage(flowerImage);
context.presentation.bindings.add(myShape, PowerPoint.BindingType.shape, bindingId);
await context.sync();
const bindingsDropdown = document.getElementById("bindings-dropdown") as HTMLSelectElement;
const option = new Option(`Binding ${bindingId}`, bindingId);
// When a binding ID already exists, the binding is updated to refer to the new shape
// so select the existing item rather than add a new one.
const foundIndex = findDropdownItem(bindingsDropdown, option.text);
if (foundIndex < 0) {
bindingsDropdown.add(option);
bindingsDropdown.selectedIndex = bindingsDropdown.options.length - 1;
} else {
bindingsDropdown.selectedIndex = foundIndex;
}
});
add(shape, bindingType, id)
特定の Shape に新しいバインドを追加します。 指定した ID がバインドによって既に使用されている場合は、既存のバインドが上書きされます。
add(shape: PowerPoint.Shape, bindingType: "Shape", id: string): PowerPoint.Binding;
パラメーター
- shape
- PowerPoint.Shape
バインドが追加される図形。
- bindingType
-
"Shape"
バインドの種類。
BindingType
を参照してください。
- id
-
string
バインドの ID。
戻り値
注釈
addFromSelection(bindingType, id)
現在の選択に基づいて新しいバインドを追加します。 選択範囲に複数の領域がある場合は、 InvalidReference エラーが返されます。
addFromSelection(bindingType: PowerPoint.BindingType, id: string): PowerPoint.Binding;
パラメーター
- bindingType
- PowerPoint.BindingType
バインドの種類。
BindingType
を参照してください。
- id
-
string
バインドの ID。
戻り値
注釈
addFromSelection(bindingType, id)
現在の選択に基づいて新しいバインドを追加します。 選択範囲に複数の領域がある場合は、 InvalidReference エラーが返されます。
addFromSelection(bindingType: "Shape", id: string): PowerPoint.Binding;
パラメーター
- bindingType
-
"Shape"
バインドの種類。
BindingType
を参照してください。
- id
-
string
バインドの ID。
戻り値
注釈
getCount()
コレクションに含まれるバインドの数を取得します。
getCount(): OfficeExtension.ClientResult<number>;
戻り値
OfficeExtension.ClientResult<number>
注釈
getItem(key)
ID を使用してバインド オブジェクトを取得します。 その ID とのバインドがない場合は、ItemNotFoundException をスローします。
getItem(key: string): PowerPoint.Binding;
パラメーター
- key
-
string
取得するバインド オブジェクトの ID。
戻り値
注釈
[ API セット: PowerPointApi 1.8 ]
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
async function getShapeForBindingId(bindingId: string): Promise<PowerPoint.Shape | undefined> {
// Gets shape associated with binding ID.
return PowerPoint.run(async (context) => {
const binding = context.presentation.bindings.getItem(bindingId);
const shape = binding.getShape();
return shape;
});
}
getItemAt(index)
項目の配列内の位置に基づいて、バインド オブジェクトを取得します。 インデックスが 0 より小さい場合、またはコレクション内の項目の数以上の場合は、InvalidArgumentException をスローします。
getItemAt(index: number): PowerPoint.Binding;
パラメーター
- index
-
number
取得するオブジェクトのインデックス値。 0 を起点とする番号になります。
戻り値
注釈
getItemOrNullObject(id)
ID を使用してバインド オブジェクトを取得します。 バインド オブジェクトが存在しない場合、このメソッドは isNullObject プロパティを true に設定したオブジェクトを返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
getItemOrNullObject(id: string): PowerPoint.Binding;
パラメーター
- id
-
string
取得するバインド オブジェクトの ID。
戻り値
注釈
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(options?: PowerPoint.Interfaces.BindingCollectionLoadOptions & PowerPoint.Interfaces.CollectionLoadOptions): PowerPoint.BindingCollection;
パラメーター
- options
-
PowerPoint.Interfaces.BindingCollectionLoadOptions & PowerPoint.Interfaces.CollectionLoadOptions
読み込むオブジェクトのプロパティのオプションを提供します。
戻り値
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNames?: string | string[]): PowerPoint.BindingCollection;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。
戻り値
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。
load(propertyNamesAndPaths?: OfficeExtension.LoadOption): PowerPoint.BindingCollection;
パラメーター
- propertyNamesAndPaths
- OfficeExtension.LoadOption
propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列で、 propertyNamesAndPaths.expand は読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。
戻り値
toJSON()
API オブジェクトがJSON.stringify()に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (JSON.stringify、それに渡されるオブジェクトの toJSON メソッドを呼び出します)。元の PowerPoint.BindingCollection オブジェクトは API オブジェクトですが、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( PowerPoint.Interfaces.BindingCollectionDataとして型指定) を返します。
toJSON(): PowerPoint.Interfaces.BindingCollectionData;