PowerPoint.Slide class

プレゼンテーションの 1 枚のスライドを表します。

Extends

注釈

API セット: PowerPointApi 1.2

使用元

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

// Reselects shapes that were saved previously.
await PowerPoint.run(async (context) => {
  const slide1: PowerPoint.Slide = context.presentation.slides.getItem(savedSlideSelection[0]);
  await context.sync();
  slide1.setSelectedShapes(savedShapeSelection);
  await context.sync();
});

プロパティ

background

スライドの背景を取得します。

context

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

customXmlParts

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

hyperlinks

スライド内のハイパーリンクのコレクションを返します。

id

スライドの一意の ID を取得します。

index

プレゼンテーション内のスライドの位置を表す、0 から始まるインデックスを返します。

layout

スライドのレイアウトを取得します。

shapes

スライド内の図形のコレクションを返します。

slideMaster

スライドの既定のコンテンツを表す SlideMaster オブジェクトを取得します。

tags

スライド内のタグのコレクションを返します。

themeColorScheme

スライドの ThemeColorScheme を返します。

メソッド

applyLayout(slideLayout)

指定したレイアウトをスライドに適用し、選択したレイアウトに従ってデザインや構造を変更します。

delete()

プレゼンテーションからスライドを削除します。 スライドが存在しない場合は、何も行いません。

exportAsBase64()

Base64 でエンコードされたデータとして返される独自のプレゼンテーション ファイルにスライドをエクスポートします。

注: この方法は、1 枚のスライドをエクスポートするために最適化されています。 複数のスライドをエクスポートすると、パフォーマンスに影響する可能性があります。

getImageAsBase64(options)

スライドの画像をレンダリングします。 画像は、目的の寸法に収まるようにスケーリングされます。 幅と高さが指定されていない場合は、スライドの実際のサイズが使用されます。 幅または高さのどちらか一方のみを指定した場合は、縦横比を保持するためにもう一方が計算されます。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

moveTo(slideIndex)

スライドをプレゼンテーション内の新しい位置に移動します。

setSelectedShapes(shapeIds)

指定した図形を選択します。 既存の図形の選択は、新しい選択に置き換えられます。

toJSON()

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

プロパティの詳細

background

スライドの背景を取得します。

readonly background: PowerPoint.SlideBackground;

プロパティ値

注釈

API セット: PowerPointApi 1.10

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

// Gets the background fill type of the first selected slide.
await PowerPoint.run(async (context) => {
  const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
  const fill: PowerPoint.SlideBackgroundFill = slide.background.fill;
  fill.load("type");
  await context.sync();

  const fillType = fill.type as PowerPoint.SlideBackgroundFillType;
  console.log(`Background fill type: ${fillType}`);
});

context

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

context: RequestContext;

プロパティ値

customXmlParts

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

readonly customXmlParts: PowerPoint.CustomXmlPartCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.7

スライド内のハイパーリンクのコレクションを返します。

readonly hyperlinks: PowerPoint.HyperlinkCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.6

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

// Sets a hyperlink on the first selected shape.
await PowerPoint.run(async (context) => {
  const slide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
  const shape: PowerPoint.Shape = context.presentation.getSelectedShapes().getItemAt(0).load("id,type");
  const hyperlinks: PowerPoint.HyperlinkCollection = slide.hyperlinks;
  const hyperlinkAddOptions: PowerPoint.HyperlinkAddOptions = {
    address: "https://bing.com",
    screenTip: "Screen tip for shape",
  };
  let hyperlink: PowerPoint.Hyperlink = hyperlinks.add(shape, 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(
    `Added link "${hyperlink.address}" (screen tip: "${hyperlink.screenTip}") to the first selected shape (ID: ${shape.id}, type: ${shape.type}).`,
  );
});

id

スライドの一意の ID を取得します。

readonly id: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.2

index

プレゼンテーション内のスライドの位置を表す、0 から始まるインデックスを返します。

readonly index: number;

プロパティ値

number

注釈

API セット: PowerPointApi 1.8

layout

スライドのレイアウトを取得します。

readonly layout: PowerPoint.SlideLayout;

プロパティ値

注釈

API セット: PowerPointApi 1.3

shapes

スライド内の図形のコレクションを返します。

readonly shapes: PowerPoint.ShapeCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.3

slideMaster

スライドの既定のコンテンツを表す SlideMaster オブジェクトを取得します。

readonly slideMaster: PowerPoint.SlideMaster;

プロパティ値

注釈

API セット: PowerPointApi 1.3

tags

スライド内のタグのコレクションを返します。

readonly tags: PowerPoint.TagCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.3

themeColorScheme

スライドの ThemeColorScheme を返します。

readonly themeColorScheme: PowerPoint.ThemeColorScheme;

プロパティ値

注釈

API セット: PowerPointApi 1.10

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-set-theme-color-scheme.yaml

// Gets the theme color scheme for the first slide and logs all theme color values.
await PowerPoint.run(async (context) => {
  const slide = context.presentation.slides.getItemAt(0);
  const colorScheme: PowerPoint.ThemeColorScheme = slide.themeColorScheme;

  // Queue up getThemeColor calls for each theme color.
  const colorResults = themeColorNames.map((colorName) => colorScheme.getThemeColor(colorName));
  await context.sync();

  // Display the results.
  console.log("Theme colors for slide 1:");
  themeColorNames.forEach((colorName, index) => {
    console.log(`  ${colorName}: ${colorResults[index].value}`);
  });
});

メソッドの詳細

applyLayout(slideLayout)

指定したレイアウトをスライドに適用し、選択したレイアウトに従ってデザインや構造を変更します。

applyLayout(slideLayout: PowerPoint.SlideLayout): void;

パラメーター

slideLayout
PowerPoint.SlideLayout

スライドに適用するレイアウト。 これは通常、スライド マスターであらかじめ定義されたレイアウトのインスタンスです。

返品

void

注釈

API セット: PowerPointApi 1.8

delete()

プレゼンテーションからスライドを削除します。 スライドが存在しない場合は、何も行いません。

delete(): void;

返品

void

注釈

API セット: PowerPointApi 1.2

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

// Deletes the selected slides.
await PowerPoint.run(async (context) => {
  context.presentation.load("slides");
  await context.sync();
  const slides: PowerPoint.SlideScopedCollection = context.presentation.getSelectedSlides();
  const slideCount = slides.getCount();
  slides.load("items");
  await context.sync();
  slides.items.map((slide) => {
    slide.delete();
  });
});

exportAsBase64()

Base64 でエンコードされたデータとして返される独自のプレゼンテーション ファイルにスライドをエクスポートします。

注: この方法は、1 枚のスライドをエクスポートするために最適化されています。 複数のスライドをエクスポートすると、パフォーマンスに影響する可能性があります。

exportAsBase64(): OfficeExtension.ClientResult<string>;

返品

注釈

API セット: PowerPointApi 1.8

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

// Exports current slide.
await PowerPoint.run(async (context) => {
  const slide = context.presentation.getSelectedSlides().getItemAt(0);
  const slideBase64DataResult = slide.exportAsBase64();
  const imageBase64DataResult = slide.getImageAsBase64({ height: 300 });
  await context.sync();

  localStorage.setItem("exportedSlide", slideBase64DataResult.value);
  localStorage.setItem("exportedSlideImage", imageBase64DataResult.value);

  updateSlideImage(imageBase64DataResult.value);

  console.log("Slide was exported.");
});

getImageAsBase64(options)

スライドの画像をレンダリングします。 画像は、目的の寸法に収まるようにスケーリングされます。 幅と高さが指定されていない場合は、スライドの実際のサイズが使用されます。 幅または高さのどちらか一方のみを指定した場合は、縦横比を保持するためにもう一方が計算されます。

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

パラメーター

options
PowerPoint.SlideGetImageOptions

省略可能。 スライド イメージの目的のサイズを指定するオプション。

返品

PNG 形式のスライド イメージの Base64 でエンコードされた文字列。

注釈

API セット: PowerPointApi 1.8

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

// Exports current slide.
await PowerPoint.run(async (context) => {
  const slide = context.presentation.getSelectedSlides().getItemAt(0);
  const slideBase64DataResult = slide.exportAsBase64();
  const imageBase64DataResult = slide.getImageAsBase64({ height: 300 });
  await context.sync();

  localStorage.setItem("exportedSlide", slideBase64DataResult.value);
  localStorage.setItem("exportedSlideImage", imageBase64DataResult.value);

  updateSlideImage(imageBase64DataResult.value);

  console.log("Slide was exported.");
});

load(options)

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

load(options?: PowerPoint.Interfaces.SlideLoadOptions): PowerPoint.Slide;

パラメーター

options
PowerPoint.Interfaces.SlideLoadOptions

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

返品

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

返品

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

返品

moveTo(slideIndex)

スライドをプレゼンテーション内の新しい位置に移動します。

moveTo(slideIndex: number): void;

パラメーター

slideIndex

number

スライドを移動する 0 から始まるインデックス。

返品

void

注釈

API セット: PowerPointApi 1.8

setSelectedShapes(shapeIds)

指定した図形を選択します。 既存の図形の選択は、新しい選択に置き換えられます。

setSelectedShapes(shapeIds: string[]): void;

パラメーター

shapeIds

string[]

スライドで選択する図形 ID の一覧。 一覧が空の場合、選択はクリアされます。

返品

void

注釈

API セット: PowerPointApi 1.5

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

// Reselects shapes that were saved previously.
await PowerPoint.run(async (context) => {
  const slide1: PowerPoint.Slide = context.presentation.slides.getItem(savedSlideSelection[0]);
  await context.sync();
  slide1.setSelectedShapes(savedShapeSelection);
  await context.sync();
});

...

// Selects the first two shapes on slide 1.
await PowerPoint.run(async (context) => {
  context.presentation.load("slides");
  await context.sync();
  const slide1 = context.presentation.slides.getItemAt(0);
  slide1.load("shapes/items/type");
  await context.sync();

  const shapes = slide1.shapes.items.filter((item) => item.type === PowerPoint.ShapeType.geometricShape);
  const shape1: PowerPoint.Shape = shapes[0];
  const shape2: PowerPoint.Shape = shapes[1];
  shape1.load("id");
  shape2.load("id");
  await context.sync();

  console.log(`IDs: ${shape1.id}, ${shape2.id}`);
  slide1.setSelectedShapes([shape1.id, shape2.id]);
  await context.sync();
});

toJSON()

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

toJSON(): PowerPoint.Interfaces.SlideData;

返品