PowerPoint.Shape class

スライド内の単一の図形を表します。

Extends

注釈

API セット: PowerPointApi 1.3

使用元

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

// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
  // Get the type of shape for every shape in the collection.
  const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
  shapes.load("type");
  await context.sync();

  // Change the shape transparency to be halfway transparent.
  shapes.items.forEach((shape) => {
    if (shape.type === PowerPoint.ShapeType.geometricShape) {
      shape.fill.transparency = 0.5;
    }
  });
  await context.sync();
});

プロパティ

adjustments

この図形のすべての調整の調整値を含む Adjustments オブジェクトを返します。

altTextDescription

図形の代替テキストの説明。

代替テキストは、図形に含まれる情報の代替テキスト ベースの表現を提供します。 この情報は、形を見たり理解したりできない視覚または認知障害のあるユーザーに役立ちます。

altTextTitle

図形の代替テキスト タイトル。

代替テキストは、図形に含まれる情報の代替テキスト ベースの表現を提供します。 この情報は、形を見たり理解したりできない視覚または認知障害のあるユーザーに役立ちます。 タイトルは障碍のある人に読み上げることができ、コンテンツの説明を聞くかどうかを判断するために使用されます。

context

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

creationId

図形の作成 ID を取得します。 図形に作成 ID がない場合は null を返します。

customXmlParts

図形内のカスタム XML パーツのコレクションを返します。

fill

この図形の塗りつぶしの書式設定を返します。

group

図形に関連付けられている ShapeGroup を返します。 図形の種類が groupでない場合、このメソッドは GeneralException エラーを返します。

height

図形の高さをポイント単位で指定します。 負の値に設定されている場合は、 InvalidArgument 例外をスローします。

id

図形の一意の ID を取得します。

isDecorative

図形が装飾的かどうかを表します。

装飾的なオブジェクトは視覚的な興味をそそりますが、情報的ではありません (様式的な罫線など)。 スクリーン リーダーを使用している People は、これらが装飾用であると読み上げられるため、重要な情報を聞き逃しているわけではないことがわかります。

left

図形の左側からスライドの左側までの距離 (ポイント単位)。

level

指定された図形のレベルを返します。

  • レベル 0 は、図形がグループの一部ではないことを意味します。

  • レベル 1 は、図形が最上位グループの一部であることを意味します。

  • レベルが 1 より大きい場合、図形が入れ子になったグループであることを示します。

lineFormat

この図形の線の書式設定を返します。

name

この図形の名前を指定します。

parentGroup

この図形の親グループを返します。 図形がグループに含まれていない場合、このメソッドは GeneralException エラーを返します。

placeholderFormat

特にこのプレースホルダーに適用されるプロパティを返します。 図形の種類が placeholderでない場合、このメソッドは GeneralException エラーを返します。

rotation

z 軸を中心とした図形の回転を度数で指定します。 正の値は時計回りの回転を示し、負の値は反時計回りの回転を示します。

tags

図形内のタグのコレクションを返します。

textFrame

このShapePowerPoint.TextFrame オブジェクトを返します。 図形がTextFrameをサポートしていない場合は、InvalidArgument例外をスローします。

top

図形の上端からスライドの上端までの距離 (ポイント単位)。

type

この図形の種類を返します。 詳細については 、PowerPoint.ShapeType を参照してください。

visible

図形を表示するかどうかを指定します。

width

図形の幅をポイント単位で指定します。 負の値に設定されている場合は、 InvalidArgument 例外をスローします。

zOrderPosition

図形の z オーダー位置を返します。0 はスタックの下部を表します。 スライド上のすべての図形に一意の Z オーダーが設定されていますが、スライドごとに一意の Z オーダーのスタックもあるため、別々のスライド上の 2 つの図形に同じ Z オーダー番号を付けることができます。

メソッド

delete()

図形コレクションから図形を削除します。 図形が存在しない場合は何も行いません。

getGraphicOrNullObject()

この図形が ShapeType.graphic の場合、PowerPoint.Graphic オブジェクトを返します。 この図形が Graphicではない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getImageAsBase64(options)

図形の画像をレンダリングします。

getParentSlide()

このShapeを保持する親 PowerPoint.Slide オブジェクトを返します。 この図形が Slideに属していない場合は例外をスローします。

getParentSlideLayout()

このShapeを保持する親 PowerPoint.SlideLayout オブジェクトを返します。 この図形が SlideLayoutに属していない場合は例外をスローします。

getParentSlideLayoutOrNullObject()

このShapeを保持する親 PowerPoint.SlideLayout オブジェクトを返します。 この図形が SlideLayoutに属していない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getParentSlideMaster()

このShapeを保持する親 PowerPoint.SlideMaster オブジェクトを返します。 この図形が SlideMasterに属していない場合は例外をスローします。

getParentSlideMasterOrNullObject()

このShapeを保持する親 PowerPoint.SlideMaster オブジェクトを返します。 この図形が SlideMasterに属していない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getParentSlideOrNullObject()

このShapeを保持する親 PowerPoint.Slide オブジェクトを返します。 この図形が Slideに属していない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getTable()

図形がテーブルの場合、 Table オブジェクトを返します。

getTextFrameOrNullObject()

このShapePowerPoint.TextFrame オブジェクトを返します。 図形が TextFrameをサポートしていない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

setHyperlink(options)

指定したオプションを使用して、この Shape にハイパーリンクを設定します。 これにより、この Shapeの既存のハイパーリンクが削除されます。

setZOrder(position)

指定された図形をコレクションの z オーダーで上または下に移動します。他の図形の手前または奥に移動します。

setZOrder(position)

指定された図形をコレクションの z オーダーで上または下に移動します。他の図形の手前または奥に移動します。

toJSON()

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

プロパティの詳細

adjustments

この図形のすべての調整の調整値を含む Adjustments オブジェクトを返します。

readonly adjustments: PowerPoint.Adjustments;

プロパティ値

注釈

API セット: PowerPointApi 1.10

altTextDescription

図形の代替テキストの説明。

代替テキストは、図形に含まれる情報の代替テキスト ベースの表現を提供します。 この情報は、形を見たり理解したりできない視覚または認知障害のあるユーザーに役立ちます。

altTextDescription: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.10

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/add-picture.yaml

// Reads the accessibility properties of the first selected shape.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  await context.sync();

  if (shapeCount.value === 0) {
    console.warn("No shapes are selected. Select a shape on the slide and try again.");
    return;
  }

  const shape: PowerPoint.Shape = shapes.getItemAt(0);
  shape.load("id,name,altTextTitle,altTextDescription,isDecorative");
  await context.sync();

  console.log(`Shape ID: ${shape.id}`);
  console.log(`Name: "${shape.name}"`);
  console.log(`Alt text title: "${shape.altTextTitle}"`);
  console.log(`Alt text description: "${shape.altTextDescription}"`);
  console.log(`Is decorative: ${shape.isDecorative}`);
});

altTextTitle

図形の代替テキスト タイトル。

代替テキストは、図形に含まれる情報の代替テキスト ベースの表現を提供します。 この情報は、形を見たり理解したりできない視覚または認知障害のあるユーザーに役立ちます。 タイトルは障碍のある人に読み上げることができ、コンテンツの説明を聞くかどうかを判断するために使用されます。

altTextTitle: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.10

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/add-picture.yaml

// Insert a picture on the current slide.
await PowerPoint.run(async (context) => {
  const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);

  // Use PictureAddOptions to control the position and dimensions (in points).
  const options: PowerPoint.PictureAddOptions = {
    left: 100,
    top: 100,
    width: 250,
    height: 180,
  };

  const picture: PowerPoint.Shape = slide.shapes.addPicture(getSampleImageBase64(), options);
  picture.name = "SamplePicture";

  // Set accessibility properties on the inserted picture.
  picture.altTextTitle = "Sample image";
  picture.altTextDescription = "A cartoon dog image used as a sample picture in this add-in.";

  await context.sync();
});

context

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

context: RequestContext;

プロパティ値

creationId

図形の作成 ID を取得します。 図形に作成 ID がない場合は null を返します。

readonly creationId: string | null;

プロパティ値

string | null

注釈

API セット: PowerPointApi 1.10

customXmlParts

図形内のカスタム XML パーツのコレクションを返します。

readonly customXmlParts: PowerPoint.CustomXmlPartCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.7

fill

この図形の塗りつぶしの書式設定を返します。

readonly fill: PowerPoint.ShapeFill;

プロパティ値

注釈

API セット: PowerPointApi 1.4

// 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();
});

group

図形に関連付けられている ShapeGroup を返します。 図形の種類が groupでない場合、このメソッドは GeneralException エラーを返します。

readonly group: PowerPoint.ShapeGroup;

プロパティ値

注釈

API セット: PowerPointApi 1.8

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

await PowerPoint.run(async (context) => {
  // Ungroups the first shape group on the current slide.

  // Get the shapes on the current slide.
  context.presentation.load("slides");
  const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
  slide.load("shapes/items/type,shapes/items/id");
  await context.sync();

  const shapes: PowerPoint.ShapeCollection = slide.shapes;
  const shapeGroups = shapes.items.filter((item) => item.type === PowerPoint.ShapeType.group);
  if (shapeGroups.length === 0) {
    console.warn("No shape groups on the current slide, so nothing to ungroup.");
    return;
  }

  // Ungroup the first grouped shapes.
  const firstGroupId = shapeGroups[0].id;
  const shapeGroupToUngroup = shapes.getItem(firstGroupId);
  shapeGroupToUngroup.group.ungroup();
  await context.sync();

  console.log(`Ungrouped shapes with group ID: ${firstGroupId}`);
});

height

図形の高さをポイント単位で指定します。 負の値に設定されている場合は、 InvalidArgument 例外をスローします。

height: number;

プロパティ値

number

注釈

API セット: PowerPointApi 1.4

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

// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items");
  await context.sync();
  let maxHeight = 0;
  shapes.items.map((shape) => {
    shape.load("width,height");
  });
  await context.sync();
  shapes.items.map((shape) => {
    shape.left = currentLeft;
    shape.top = currentTop;
    currentLeft += shape.width;
    if (shape.height > maxHeight) maxHeight = shape.height;
  });
  await context.sync();
  currentLeft = 0;
  if (currentTop > slideHeight - 200) currentTop = 0;
});

id

図形の一意の ID を取得します。

readonly id: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.3

isDecorative

図形が装飾的かどうかを表します。

装飾的なオブジェクトは視覚的な興味をそそりますが、情報的ではありません (様式的な罫線など)。 スクリーン リーダーを使用している People は、これらが装飾用であると読み上げられるため、重要な情報を聞き逃しているわけではないことがわかります。

isDecorative: boolean;

プロパティ値

boolean

注釈

API セット: PowerPointApi 1.10

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/add-picture.yaml

// Toggles the isDecorative property on the first selected shape.
// When isDecorative is true, screen readers announce the shape as
// decorative, indicating no alt text is needed.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  await context.sync();

  if (shapeCount.value === 0) {
    console.warn("No shapes are selected. Select a shape on the slide and try again.");
    return;
  }

  const shape: PowerPoint.Shape = shapes.getItemAt(0);
  shape.load("name,isDecorative");
  await context.sync();

  const wasDecorative = shape.isDecorative;
  shape.isDecorative = !wasDecorative;
  await context.sync();

  console.log(`Shape "${shape.name}" isDecorative changed: ${wasDecorative} → ${shape.isDecorative}`);
});

left

図形の左側からスライドの左側までの距離 (ポイント単位)。

left: number;

プロパティ値

number

注釈

API セット: PowerPointApi 1.4

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

// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items");
  await context.sync();
  let maxHeight = 0;
  shapes.items.map((shape) => {
    shape.load("width,height");
  });
  await context.sync();
  shapes.items.map((shape) => {
    shape.left = currentLeft;
    shape.top = currentTop;
    currentLeft += shape.width;
    if (shape.height > maxHeight) maxHeight = shape.height;
  });
  await context.sync();
  currentLeft = 0;
  if (currentTop > slideHeight - 200) currentTop = 0;
});

level

指定された図形のレベルを返します。

  • レベル 0 は、図形がグループの一部ではないことを意味します。

  • レベル 1 は、図形が最上位グループの一部であることを意味します。

  • レベルが 1 より大きい場合、図形が入れ子になったグループであることを示します。

readonly level: number;

プロパティ値

number

注釈

API セット: PowerPointApi 1.8

lineFormat

この図形の線の書式設定を返します。

readonly lineFormat: PowerPoint.ShapeLineFormat;

プロパティ値

注釈

API セット: PowerPointApi 1.4

name

この図形の名前を指定します。

name: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.4

parentGroup

この図形の親グループを返します。 図形がグループに含まれていない場合、このメソッドは GeneralException エラーを返します。

readonly parentGroup: PowerPoint.Shape;

プロパティ値

注釈

API セット: PowerPointApi 1.8

placeholderFormat

特にこのプレースホルダーに適用されるプロパティを返します。 図形の種類が placeholderでない場合、このメソッドは GeneralException エラーを返します。

readonly placeholderFormat: PowerPoint.PlaceholderFormat;

プロパティ値

注釈

API セット: PowerPointApi 1.8

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

// Gets the placeholder shapes in the slide.
await PowerPoint.run(async (context) => {
  // Get properties for every shape in the collection.
  const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
  shapes.load("type,name");
  await context.sync();

  const placeholderShapes = [];
  console.log(`Number of shapes found: ${shapes.items.length}`);
  shapes.items.forEach((shape) => {
    if (shape.type === PowerPoint.ShapeType.placeholder) {
      // Load placeholderFormat property.
      // PowerPoint throws an exception if you try to load this property on a shape that isn't a placeholder type.
      shape.load("placeholderFormat");
      placeholderShapes.push(shape);
    }
  });
  await context.sync();

  console.log(`Number of placeholder shapes found: ${placeholderShapes.length}`);
  for (let i = 0; i < placeholderShapes.length; i++) {
    let currentPlaceholder: PowerPoint.PlaceholderFormat = placeholderShapes[i].placeholderFormat;
    let placeholderType = currentPlaceholder.type as PowerPoint.PlaceholderType;
    let placeholderContainedType = currentPlaceholder.containedType as PowerPoint.ShapeType;
    console.log(`Shape "${placeholderShapes[i].name}" placeholder properties:`);
    console.log(`\ttype: ${placeholderType}`);
    console.log(`\tcontainedType: ${placeholderContainedType}`);
  }
});

rotation

z 軸を中心とした図形の回転を度数で指定します。 正の値は時計回りの回転を示し、負の値は反時計回りの回転を示します。

rotation: number;

プロパティ値

number

注釈

API セット: PowerPointApi 1.10

tags

図形内のタグのコレクションを返します。

readonly tags: PowerPoint.TagCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.3

textFrame

このShapePowerPoint.TextFrame オブジェクトを返します。 図形がTextFrameをサポートしていない場合は、InvalidArgument例外をスローします。

readonly textFrame: PowerPoint.TextFrame;

プロパティ値

注釈

API セット: PowerPointApi 1.4

top

図形の上端からスライドの上端までの距離 (ポイント単位)。

top: number;

プロパティ値

number

注釈

API セット: PowerPointApi 1.4

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

// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items");
  await context.sync();
  let maxHeight = 0;
  shapes.items.map((shape) => {
    shape.load("width,height");
  });
  await context.sync();
  shapes.items.map((shape) => {
    shape.left = currentLeft;
    shape.top = currentTop;
    currentLeft += shape.width;
    if (shape.height > maxHeight) maxHeight = shape.height;
  });
  await context.sync();
  currentLeft = 0;
  if (currentTop > slideHeight - 200) currentTop = 0;
});

type

この図形の種類を返します。 詳細については 、PowerPoint.ShapeType を参照してください。

readonly type: PowerPoint.ShapeType | "Unsupported" | "Image" | "GeometricShape" | "Group" | "Line" | "Table" | "Callout" | "Chart" | "ContentApp" | "Diagram" | "Freeform" | "Graphic" | "Ink" | "Media" | "Model3D" | "Ole" | "Placeholder" | "SmartArt" | "TextBox";

プロパティ値

PowerPoint.ShapeType | "Unsupported" | "Image" | "GeometricShape" | "Group" | "Line" | "Table" | "Callout" | "Chart" | "ContentApp" | "Diagram" | "Freeform" | "Graphic" | "Ink" | "Media" | "Model3D" | "Ole" | "Placeholder" | "SmartArt" | "TextBox"

注釈

API セット: PowerPointApi 1.4

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

// Changes the transparency of every geometric shape in the slide.
await PowerPoint.run(async (context) => {
  // Get the type of shape for every shape in the collection.
  const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
  shapes.load("type");
  await context.sync();

  // Change the shape transparency to be halfway transparent.
  shapes.items.forEach((shape) => {
    if (shape.type === PowerPoint.ShapeType.geometricShape) {
      shape.fill.transparency = 0.5;
    }
  });
  await context.sync();
});

visible

図形を表示するかどうかを指定します。

visible: boolean;

プロパティ値

boolean

注釈

API セット: PowerPointApi 1.10

width

図形の幅をポイント単位で指定します。 負の値に設定されている場合は、 InvalidArgument 例外をスローします。

width: number;

プロパティ値

number

注釈

API セット: PowerPointApi 1.4

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

// Arranges the selected shapes in a line from left to right.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items");
  await context.sync();
  let maxHeight = 0;
  shapes.items.map((shape) => {
    shape.load("width,height");
  });
  await context.sync();
  shapes.items.map((shape) => {
    shape.left = currentLeft;
    shape.top = currentTop;
    currentLeft += shape.width;
    if (shape.height > maxHeight) maxHeight = shape.height;
  });
  await context.sync();
  currentLeft = 0;
  if (currentTop > slideHeight - 200) currentTop = 0;
});

zOrderPosition

図形の z オーダー位置を返します。0 はスタックの下部を表します。 スライド上のすべての図形に一意の Z オーダーが設定されていますが、スライドごとに一意の Z オーダーのスタックもあるため、別々のスライド上の 2 つの図形に同じ Z オーダー番号を付けることができます。

readonly zOrderPosition: number;

プロパティ値

number

注釈

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 changeZOrder(operation: PowerPoint.ShapeZOrder) {
  // Changes the z-order position of the selected shapes.
  return PowerPoint.run(async (context) => {
    const selectedShapes = context.presentation.getSelectedShapes();
    selectedShapes.load();
    await context.sync();

    if (selectedShapes.items.length === 0) {
      console.log("No shapes are selected.");
    } else {
      let direction = 1; // Start with bottom-most (lowest number).

      // Start with top-most when sending to back or bringing forward.

      switch (operation) {
        case PowerPoint.ShapeZOrder.bringForward:

        case PowerPoint.ShapeZOrder.sendToBack:
          direction = -1; // Reverse direction.

          break;
      }

      // Change the z-order position for each of the selected shapes,

      // starting with the bottom-most when bringing to front or sending backward,

      // or top-most when sending to back or bringing forward,

      // so the selected shapes retain their relative z-order positions after they're changed.

      selectedShapes.items
        .sort((a, b) => (a.zOrderPosition - b.zOrderPosition) * direction)
        .forEach((shape) => {
          try {
            const originalZOrderPosition = shape.zOrderPosition;
            shape.setZOrder(operation);

            console.log(`Changed z-order of shape ${shape.id}.`);
          } catch (err) {
            console.log(`Unable to change z-order of shape ${shape.id}. ${err.message}`);
          }
        });

      await context.sync();
    }
  });
}

メソッドの詳細

delete()

図形コレクションから図形を削除します。 図形が存在しない場合は何も行いません。

delete(): void;

返品

void

注釈

API セット: PowerPointApi 1.3

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

// This function gets the collection of shapes on the first slide,
// and then iterates through them, deleting each one.
await PowerPoint.run(async (context) => {
  const slide: PowerPoint.Slide = context.presentation.slides.getItemAt(0);
  const shapes: PowerPoint.ShapeCollection = slide.shapes;

  // Load all the shapes in the collection without loading their properties.
  shapes.load("items/$none");

  await context.sync();

  shapes.items.forEach((shape) => shape.delete());

  await context.sync();
});

getGraphicOrNullObject()

注意

この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。

この図形が ShapeType.graphic の場合、PowerPoint.Graphic オブジェクトを返します。 この図形が Graphicではない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getGraphicOrNullObject(): PowerPoint.Graphic;

返品

注釈

API セット: PowerPointApi ベータ版 (プレビューのみ)

getImageAsBase64(options)

図形の画像をレンダリングします。

getImageAsBase64(options?: PowerPoint.ShapeGetImageOptions): OfficeExtension.ClientResult<string>;

パラメーター

options
PowerPoint.ShapeGetImageOptions

省略可能。 目的の出力イメージ プロパティを指定するオプション。

返品

指定した形式の図形イメージの Base64 エンコード文字列。

注釈

API セット: PowerPointApi 1.10

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

// Gets an image of the first selected shape using default options
// (PNG format at the shape's original size).
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  await context.sync();

  if (shapeCount.value === 0) {
    console.warn("No shapes are selected. Please select a shape and try again.");
    return;
  }

  const shape: PowerPoint.Shape = shapes.getItemAt(0);
  // Call getImageAsBase64 with no options - returns PNG at the shape's true size.
  const imageResult: OfficeExtension.ClientResult<string> = shape.getImageAsBase64();
  await context.sync();

  displayImage(imageResult.value, "Default (original size, PNG)");
});

getParentSlide()

このShapeを保持する親 PowerPoint.Slide オブジェクトを返します。 この図形が Slideに属していない場合は例外をスローします。

getParentSlide(): PowerPoint.Slide;

返品

注釈

API セット: PowerPointApi 1.5

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

// Gets navigational (complex) properties of the selected text range.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.load("font,paragraphFormat/bulletFormat,paragraphFormat/horizontalAlignment");

  const parentTextFrame: PowerPoint.TextFrame = textRange.getParentTextFrame();
  const parentShape: PowerPoint.Shape = parentTextFrame.getParentShape();
  const parentSlide: PowerPoint.Slide = parentShape.getParentSlide();
  parentShape.load("id");
  parentSlide.load("id");
  await context.sync();

  console.log(`Selected text range found in parent shape with ID ${parentShape.id} on parentSlide with ID ${parentSlide.id}`);

  console.log("Font properties of selected text range:");
  console.log(`\tallCaps: ${textRange.font.allCaps}`);
  console.log(`\tbold: ${textRange.font.bold}`);
  console.log(`\tcolor: ${textRange.font.color}`);
  console.log(`\tdoubleStrikethrough: ${textRange.font.doubleStrikethrough}`);
  console.log(`\titalic: ${textRange.font.italic}`);
  console.log(`\tname: ${textRange.font.name}`);
  console.log(`\tsize: ${textRange.font.size}`);
  console.log(`\tsmallCaps: ${textRange.font.smallCaps}`);
  console.log(`\tstrikethrough: ${textRange.font.strikethrough}`);
  console.log(`\tsubscript: ${textRange.font.subscript}`);
  console.log(`\tsuperscript: ${textRange.font.superscript}`);
  console.log(`\tunderline: ${textRange.font.underline}`);

  console.log("Paragraph format properties of selected text range:");
  console.log(`\tbulletFormat.visible: ${textRange.paragraphFormat.bulletFormat.visible}`);
  console.log(`\thorizontalAlignment: ${textRange.paragraphFormat.horizontalAlignment}`);
});

getParentSlideLayout()

このShapeを保持する親 PowerPoint.SlideLayout オブジェクトを返します。 この図形が SlideLayoutに属していない場合は例外をスローします。

getParentSlideLayout(): PowerPoint.SlideLayout;

返品

注釈

API セット: PowerPointApi 1.5

getParentSlideLayoutOrNullObject()

このShapeを保持する親 PowerPoint.SlideLayout オブジェクトを返します。 この図形が SlideLayoutに属していない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getParentSlideLayoutOrNullObject(): PowerPoint.SlideLayout;

返品

注釈

API セット: PowerPointApi 1.5

getParentSlideMaster()

このShapeを保持する親 PowerPoint.SlideMaster オブジェクトを返します。 この図形が SlideMasterに属していない場合は例外をスローします。

getParentSlideMaster(): PowerPoint.SlideMaster;

返品

注釈

API セット: PowerPointApi 1.5

getParentSlideMasterOrNullObject()

このShapeを保持する親 PowerPoint.SlideMaster オブジェクトを返します。 この図形が SlideMasterに属していない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getParentSlideMasterOrNullObject(): PowerPoint.SlideMaster;

返品

注釈

API セット: PowerPointApi 1.5

getParentSlideOrNullObject()

このShapeを保持する親 PowerPoint.Slide オブジェクトを返します。 この図形が Slideに属していない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getParentSlideOrNullObject(): PowerPoint.Slide;

返品

注釈

API セット: PowerPointApi 1.5

getTable()

図形がテーブルの場合、 Table オブジェクトを返します。

getTable(): PowerPoint.Table;

返品

注釈

API セット: PowerPointApi 1.8

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

// Gets the table from a shape.
await PowerPoint.run(async (context) => {
  const shapes = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items");
  await context.sync();

  if (shapeCount.value > 0) {
    const shape = shapes.getItemAt(0);
    shape.load("type");
    await context.sync();

    // The shape type can indicate whether the shape is a table.
    const isTable = shape.type === PowerPoint.ShapeType.table;

    if (isTable) {
      // Get the Table object for the Shape which is a table.
      const table = shape.getTable();
      table.load();
      await context.sync();

      // Get the Table row and column count.
      console.log("Table RowCount: " + table.rowCount + " and columnCount: " + table.columnCount);
    } else console.log("Selected shape isn't table.");
  } else console.log("No shape selected.");
});

getTextFrameOrNullObject()

このShapePowerPoint.TextFrame オブジェクトを返します。 図形が TextFrameをサポートしていない場合、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getTextFrameOrNullObject(): PowerPoint.TextFrame;

返品

注釈

API セット: PowerPointApi 1.10

load(options)

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

load(options?: PowerPoint.Interfaces.ShapeLoadOptions): PowerPoint.Shape;

パラメーター

options
PowerPoint.Interfaces.ShapeLoadOptions

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

返品

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

返品

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.Shape;

パラメーター

propertyNamesAndPaths

{ select?: string; expand?: string; }

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

返品

指定したオプションを使用して、この Shape にハイパーリンクを設定します。 これにより、この Shapeの既存のハイパーリンクが削除されます。

setHyperlink(options?: PowerPoint.HyperlinkAddOptions): PowerPoint.Hyperlink;

パラメーター

options
PowerPoint.HyperlinkAddOptions

省略可能。 ハイパーリンクのオプション

返品

新しく作成された PowerPoint.Hyperlink オブジェクト。

注釈

API セット: PowerPointApi 1.10

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

// Updates the hyperlink on the first selected shape on the current slide.
await PowerPoint.run(async (context) => {
  const shape: PowerPoint.Shape = context.presentation.getSelectedShapes().getItemAt(0).load("type");
  const hyperlinkAddOptions: PowerPoint.HyperlinkAddOptions = {
    address: "https://www.microsoft.com",
    screenTip: "Updated screen tip of link on shape",
  };
  const hyperlink: PowerPoint.Hyperlink = shape.setHyperlink(hyperlinkAddOptions).load("address,screenTip");
  try {
    await context.sync();
  } catch {
    console.warn("Confirm that you have at least one slide and you've selected a shape on the active slide.");
    return;
  }

  console.log(
    `Updated link on the selected ${shape.type} shape to "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}").`,
  );
});

setZOrder(position)

指定された図形をコレクションの z オーダーで上または下に移動します。他の図形の手前または奥に移動します。

setZOrder(position: PowerPoint.ShapeZOrder): void;

パラメーター

position
PowerPoint.ShapeZOrder

Z オーダー スタック内で図形を移動する方法を指定します。 ShapeZOrder 列挙型を使用します。

返品

void

注釈

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 changeZOrder(operation: PowerPoint.ShapeZOrder) {
  // Changes the z-order position of the selected shapes.
  return PowerPoint.run(async (context) => {
    const selectedShapes = context.presentation.getSelectedShapes();
    selectedShapes.load();
    await context.sync();

    if (selectedShapes.items.length === 0) {
      console.log("No shapes are selected.");
    } else {
      let direction = 1; // Start with bottom-most (lowest number).

      // Start with top-most when sending to back or bringing forward.

      switch (operation) {
        case PowerPoint.ShapeZOrder.bringForward:

        case PowerPoint.ShapeZOrder.sendToBack:
          direction = -1; // Reverse direction.

          break;
      }

      // Change the z-order position for each of the selected shapes,

      // starting with the bottom-most when bringing to front or sending backward,

      // or top-most when sending to back or bringing forward,

      // so the selected shapes retain their relative z-order positions after they're changed.

      selectedShapes.items
        .sort((a, b) => (a.zOrderPosition - b.zOrderPosition) * direction)
        .forEach((shape) => {
          try {
            const originalZOrderPosition = shape.zOrderPosition;
            shape.setZOrder(operation);

            console.log(`Changed z-order of shape ${shape.id}.`);
          } catch (err) {
            console.log(`Unable to change z-order of shape ${shape.id}. ${err.message}`);
          }
        });

      await context.sync();
    }
  });
}

setZOrder(position)

指定された図形をコレクションの z オーダーで上または下に移動します。他の図形の手前または奥に移動します。

setZOrder(position: "BringForward" | "BringToFront" | "SendBackward" | "SendToBack"): void;

パラメーター

position

"BringForward" | "BringToFront" | "SendBackward" | "SendToBack"

Z オーダー スタック内で図形を移動する方法を指定します。 ShapeZOrder 列挙型を使用します。

返品

void

注釈

API セット: PowerPointApi 1.8

toJSON()

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

toJSON(): PowerPoint.Interfaces.ShapeData;

返品