PowerPoint.ShapeScopedCollection class

図形のコレクションを表します。

Extends

注釈

API セット: PowerPointApi 1.5

使用元

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml

// Changes the selected shapes fill color to red.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items/fill/type");
  await context.sync();
  shapes.items.map((shape) => {
    const shapeFillType = shape.fill.type as PowerPoint.ShapeFillType;
    console.log(`Shape ID ${shape.id} original fill type: ${shapeFillType}`);
    shape.fill.setSolidColor("red");
  });
  await context.sync();
});

プロパティ

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

items

このコレクション内に読み込まれた子アイテムを取得します。

メソッド

getCount()

コレクション内の図形の数を取得します。

getItem(key)

一意の ID を使用して図形を取得します。 図形が存在しない場合は、エラーがスローされます。

getItemAt(index)

コレクション内の 0 から始まるインデックスを使用して図形を取得します。 インデックスが範囲外の場合は、エラーがスローされます。

getItemOrNullObject(id)

一意の ID を使用して図形を取得します。 そのような図形が存在しない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

group()

このコレクションのすべての図形を 1 つの図形にグループ化します。 コレクションに含まれる図形が 2 つ未満の場合、このメソッドは GeneralException エラーを返します。

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の PowerPoint.ShapeScopedCollection オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( PowerPoint.Interfaces.ShapeScopedCollectionData として型指定された) を返します。

プロパティの詳細

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

items

このコレクション内に読み込まれた子アイテムを取得します。

readonly items: PowerPoint.Shape[];

プロパティ値

メソッドの詳細

getCount()

コレクション内の図形の数を取得します。

getCount(): OfficeExtension.ClientResult<number>;

返品

コレクション内の図形の数。

注釈

API セット: PowerPointApi 1.5

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-set-shapes.yaml

// Gets the shapes you selected on the slide and displays their IDs on the task pane.
await PowerPoint.run(async (context) => {
  let finalTable = "";
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  await context.sync();
  finalTable += "<br>getSelectedShapes.getCount returned:<b>" + shapeCount.value + "</b><br>";
  finalTable +=
    "<br><table border=1 cellpadding=3 cellspacing=0><tr><td bgcolor=#3333EE><font color=white>Index</font></td><td bgcolor=#3333EE><font color=white>Id</font></td></tr>";
  shapes.load("items");
  await context.sync();
  shapes.items.map((shape, index) => {
    finalTable += "<tr><td>" + index + "</td><td>" + shape.id + "</td></tr>";
  });
  finalTable += "</table>";
  const outputSpan = document.getElementById("outputSpan");
  outputSpan.innerHTML = "";
  outputSpan.innerHTML += finalTable;
});

getItem(key)

一意の ID を使用して図形を取得します。 図形が存在しない場合は、エラーがスローされます。

getItem(key: string): PowerPoint.Shape;

パラメーター

key

string

図形の ID。

返品

一意の ID を持つ図形。 そのような図形が存在しない場合は、エラーがスローされます。

注釈

API セット: PowerPointApi 1.5

getItemAt(index)

コレクション内の 0 から始まるインデックスを使用して図形を取得します。 インデックスが範囲外の場合は、エラーがスローされます。

getItemAt(index: number): PowerPoint.Shape;

パラメーター

index

number

コレクション内の図形のインデックス。

返品

指定したインデックス位置の図形。 index が範囲外の場合は、エラーがスローされます。

注釈

API セット: PowerPointApi 1.5

getItemOrNullObject(id)

一意の ID を使用して図形を取得します。 そのような図形が存在しない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getItemOrNullObject(id: string): PowerPoint.Shape;

パラメーター

id

string

図形の ID。

返品

一意の ID を持つ図形。 そのような図形が存在しない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。

注釈

API セット: PowerPointApi 1.5

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shape-by-id.yaml

// Uses getItemOrNullObject to find a shape by ID within the selected shapes.
// If the ID is not found in the selected shapes, the returned object's isNullObject property is true.
await PowerPoint.run(async (context) => {
  const shapeId = (document.getElementById("shape-id-input") as HTMLInputElement).value.trim();
  if (!shapeId) {
    console.log("Enter a shape ID in the text box first.");
    return;
  }

  const selectedShapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();

  // getItemOrNullObject returns a Shape object without throwing if the ID isn't found.
  const shape: PowerPoint.Shape = selectedShapes.getItemOrNullObject(shapeId);
  shape.load("id,name,type");
  await context.sync();

  if (shape.isNullObject) {
    console.log(`Shape ID "${shapeId}" was not found in the selected shapes.`);
  } else {
    console.log(`Shape found in the selected shapes.`);
    console.log(`  ID: ${shape.id}`);
    console.log(`  Name: "${shape.name}"`);
    console.log(`  Type: ${shape.type}`);
  }
});

group()

このコレクションのすべての図形を 1 つの図形にグループ化します。 コレクションに含まれる図形が 2 つ未満の場合、このメソッドは GeneralException エラーを返します。

group(): PowerPoint.Shape;

返品

新しく作成されたグループ化された図形を PowerPoint.Shape として作成します。

注釈

API セット: PowerPointApi 1.8

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: PowerPoint.Interfaces.ShapeScopedCollectionLoadOptions & PowerPoint.Interfaces.CollectionLoadOptions): PowerPoint.ShapeScopedCollection;

パラメーター

options

PowerPoint.Interfaces.ShapeScopedCollectionLoadOptions & PowerPoint.Interfaces.CollectionLoadOptions

読み込むオブジェクトのプロパティのオプションを指定します。

返品

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames?: string | string[]): PowerPoint.ShapeScopedCollection;

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。

返品

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): PowerPoint.ShapeScopedCollection;

パラメーター

propertyNamesAndPaths
OfficeExtension.LoadOption

propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。

返品

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の PowerPoint.ShapeScopedCollection オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( PowerPoint.Interfaces.ShapeScopedCollectionData として型指定された) を返します。

toJSON(): PowerPoint.Interfaces.ShapeScopedCollectionData;

返品