PowerPoint.Presentation class

Presentation オブジェクトは、プレゼンテーションの内容を含む 1 枚以上のスライドを持つ最上位のオブジェクトです。 PowerPoint オブジェクト モデルの詳細については、「 JavaScript オブジェクト モデルPowerPoint」を参照してください。

Extends

注釈

API セット: PowerPointApi 1.0

使用元

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

await PowerPoint.run(async function(context) {
    // Get the ID of the first selected slide.
    const presentation: PowerPoint.Presentation = context.presentation;
    const selected: PowerPoint.Slide = presentation.getSelectedSlides().getItemAt(0);
    selected.load("id");
    await context.sync();

    // Insert the other presentation after the selected slide.
    const insertOptions: PowerPoint.InsertSlideOptions = {
        formatting: PowerPoint.InsertSlideFormatting.useDestinationTheme,
        targetSlideId: selected.id
    };
    presentation.insertSlidesFromBase64(chosenFileBase64, insertOptions);
    await context.sync();
});

プロパティ

bindings

プレゼンテーションに関連付けられているバインドのコレクションを返します。

context

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

customXmlParts

プレゼンテーションに関連付けられたカスタム XML パーツのコレクションを返します。

id

プレゼンテーションの ID を取得します。

pageSetup

ページ設定情報を返します。そのプロパティはプレゼンテーションのスライド設定属性を制御します。

properties

プレゼンテーションのプロパティを取得します。

sensitivityLabel

プレゼンテーションの秘密度ラベルを返します。

slideMasters

プレゼンテーション内の SlideMaster オブジェクトのコレクションを返します。

slides

プレゼンテーション内のスライドの順序付きコレクションを返します。

tags

プレゼンテーションに添付されたタグのコレクションを返します。

title

プレゼンテーションのタイトルを返します。

メソッド

getActiveSlideOrNullObject()

編集領域に表示されている現在アクティブな PowerPoint.Slide を返します。 アクティブなスライドがない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getSelectedShapes()

プレゼンテーションの現在のスライドで選択された図形を返します。 図形が選択されていない場合は、空のコレクションが返されます。

getSelectedSlides()

選択したスライドをプレゼンテーションの現在のビューで返します。 コレクションの最初の項目は、編集領域に表示されるアクティブなスライドです。 スライドが選択されていない場合は、空のコレクションが返されます。

getSelectedTextRange()

プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は例外をスローします。

getSelectedTextRangeOrNullObject()

プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

insertSlidesFromBase64(base64File, options)

プレゼンテーションから現在のプレゼンテーションに指定されたスライドを挿入します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

setSelectedSlides(slideIds)

プレゼンテーションの現在のビューでスライドを選びます。 既存のスライド選択範囲は、新しい選択範囲に置き換えられます。

toJSON()

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

イベント

onSlideSelectionChanged

プレゼンテーションのスライドの選択が変更されたときに発生します。 このイベントは、ユーザーが別のスライドを選択したとき、またはスライドの選択を変更したときに発生します。 スライド内のコンテンツ (図形など) の選択が変更された場合、このイベントは発生しません。

プロパティの詳細

bindings

プレゼンテーションに関連付けられているバインドのコレクションを返します。

readonly bindings: PowerPoint.BindingCollection;

プロパティ値

注釈

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 ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

customXmlParts

プレゼンテーションに関連付けられたカスタム XML パーツのコレクションを返します。

readonly customXmlParts: PowerPoint.CustomXmlPartCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.7

id

プレゼンテーションの ID を取得します。

readonly id: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.5

pageSetup

ページ設定情報を返します。そのプロパティはプレゼンテーションのスライド設定属性を制御します。

readonly pageSetup: PowerPoint.PageSetup;

プロパティ値

注釈

API セット: PowerPointApi 1.10

properties

プレゼンテーションのプロパティを取得します。

readonly properties: PowerPoint.DocumentProperties;

プロパティ値

注釈

API セット: PowerPointApi 1.7

sensitivityLabel

注意

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

プレゼンテーションの秘密度ラベルを返します。

readonly sensitivityLabel: PowerPoint.SensitivityLabel;

プロパティ値

注釈

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

slideMasters

プレゼンテーション内の SlideMaster オブジェクトのコレクションを返します。

readonly slideMasters: PowerPoint.SlideMasterCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.3

slides

プレゼンテーション内のスライドの順序付きコレクションを返します。

readonly slides: PowerPoint.SlideCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.2

tags

プレゼンテーションに添付されたタグのコレクションを返します。

readonly tags: PowerPoint.TagCollection;

プロパティ値

注釈

API セット: PowerPointApi 1.3

title

プレゼンテーションのタイトルを返します。

readonly title: string;

プロパティ値

string

注釈

API セット: PowerPointApi 1.0

メソッドの詳細

getActiveSlideOrNullObject()

注意

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

編集領域に表示されている現在アクティブな PowerPoint.Slide を返します。 アクティブなスライドがない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getActiveSlideOrNullObject(): PowerPoint.Slide;

返品

注釈

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

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/preview-apis/presentation-get-active-slide.yaml

await PowerPoint.run(async (context) => {
  // Gets the active slide in the presentation.
  const slide: PowerPoint.Slide = context.presentation.getActiveSlideOrNullObject();
  slide.load("id");
  const activeSlideImage = slide.getImageAsBase64({ height: 200 });
  await context.sync();

  if (slide.isNullObject) {
    console.log("There are no slides in this presentation.");
    return;
  }

  console.log(`Active slide ID: ${slide.id}`);

  updateSlideImage(activeSlideImage.value);
});

getSelectedShapes()

プレゼンテーションの現在のスライドで選択された図形を返します。 図形が選択されていない場合は、空のコレクションが返されます。

getSelectedShapes(): PowerPoint.ShapeScopedCollection;

返品

注釈

API セット: PowerPointApi 1.5

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

...

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

...

// Saves which shapes are selected so that they can be reselected later.
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();
  savedSlideSelection = [];
  slides.items.map((slide) => {
    savedSlideSelection.push(slide.id);
  });
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  shapes.load("items");
  await context.sync();
  shapes.items.map((shape) => {
    savedShapeSelection.push(shape.id);
  });
});

getSelectedSlides()

選択したスライドをプレゼンテーションの現在のビューで返します。 コレクションの最初の項目は、編集領域に表示されるアクティブなスライドです。 スライドが選択されていない場合は、空のコレクションが返されます。

getSelectedSlides(): PowerPoint.SlideScopedCollection;

返品

注釈

API セット: PowerPointApi 1.5

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

// Gets the selected slides and displays their IDs on the task pane.
await PowerPoint.run(async (context) => {
  let finalTable = "";
  context.presentation.load("slides");
  await context.sync();
  const allSlidesList = {};
  const allSlidesCount = context.presentation.slides.getCount();
  context.presentation.slides.load("items");
  await context.sync();
  let allSlideItems: PowerPoint.Slide[] = context.presentation.slides.items;
  allSlideItems.map((slide, index) => {
    allSlidesList[slide.id] = `Slide ${index + 1}`;
  });

  const checkbox = document.getElementById("id-check-usenative") as HTMLInputElement;
  if (checkbox && checkbox.checked) {
    context.presentation.load("tags");
  }

  const slides: PowerPoint.SlideScopedCollection = context.presentation.getSelectedSlides();
  const slideCount = slides.getCount();
  slides.load("items");
  await context.sync();
  finalTable += "<br>getSelectedSlides.getCount returned:<b>" + slideCount.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>";
  slides.items.map((slide, index) => {
    finalTable += "<tr><td>" + index + " - " + allSlidesList[slide.id] + "</td><td>" + slide.id + "</td></tr>";
  });
  finalTable += "</table>";
  const outputSpan = document.getElementById("outputSpan");
  outputSpan.innerHTML = ""
  outputSpan.innerHTML += finalTable;
});

...

// Saves which slides are currently selected so they can be reselected later.
await PowerPoint.run(async (context) => {
  let finalTable = "";
  context.presentation.load("slides");
  await context.sync();
  const slides: PowerPoint.SlideScopedCollection = context.presentation.getSelectedSlides();
  const slideCount = slides.getCount();
  await context.sync();
  finalTable += "<br>getSelectedSlides.getCount returned:<b>" + slideCount.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>";
  savedSlideSelection = [];
  slides.load("items");
  await context.sync();
  slides.items.map((slide, index) => {
    finalTable += "<tr><td>" + index + "</td><td>" + slide.id + "</td></tr>";
    savedSlideSelection.push(slide.id);
  });
  finalTable += "</table>";
  const outputSpan = document.getElementById("outputSpan");
  outputSpan.innerHTML = ""
  outputSpan.innerHTML += finalTable;
});

getSelectedTextRange()

プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は例外をスローします。

getSelectedTextRange(): PowerPoint.TextRange;

返品

注釈

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 the selected text range and prints data about the range on the task pane.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  try {
    await context.sync();
  } catch (error) {
    console.warn("You must select only one range of text for this action to work.");
    return;
  }
  textRange.load("text");
  textRange.load("start");
  textRange.load("length");
  await context.sync();
  let txtHtml = textRange.text;
  txtHtml = txtHtml.replace(/\n/g, "<br>");
  txtHtml = txtHtml.replace(/\r/g, "<br>");
  txtHtml = txtHtml.replace(/\v/g, "<br>");
  let txtExplained = textRange.text;
  txtExplained = txtExplained.replace(/\n/g, "<font color=red>NL</font>");
  txtExplained = txtExplained.replace(/\r/g, "<font color=red>CR</font>");
  txtExplained = txtExplained.replace(/\v/g, "<font color=red>VV</font>");
  let finalTable = "";
  finalTable +=
    "<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>";
  finalTable += "<tr><td>Raw</td><td>" + textRange.text + "</td></tr>";
  finalTable += "<tr><td>Html</td><td>" + txtHtml + "</td></tr>";
  finalTable += "<tr><td>Exp</td><td>" + txtExplained + "</td></tr>";
  finalTable += "<tr><td>Start</td><td>" + textRange.start + "</td></tr>";
  finalTable += "<tr><td>Length</td><td>" + textRange.length + "</td></tr>";
  finalTable += "</table>";
  const outputSpan = document.getElementById("outputSpan");
  outputSpan.innerHTML = "";
  outputSpan.innerHTML += finalTable;
});

...

// Sets the range selection to the range that was saved previously.
await PowerPoint.run(async (context) => {
  const slide1: PowerPoint.Slide = context.presentation.slides.getItem(savedTextSlideSelection[0]);
  const shape1: PowerPoint.Shape = slide1.shapes.getItem(savedTextShapeSelection[0]);
  const textRange: PowerPoint.TextRange = shape1.textFrame.textRange.getSubstring(
    savedTextTextRangeStart,
    savedTextTextRangeLength,
  );
  textRange.setSelected();
  await context.sync();
});

getSelectedTextRangeOrNullObject()

プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject のメソッドとプロパティ」を参照してください。

getSelectedTextRangeOrNullObject(): PowerPoint.TextRange;

返品

注釈

API セット: PowerPointApi 1.5

insertSlidesFromBase64(base64File, options)

プレゼンテーションから現在のプレゼンテーションに指定されたスライドを挿入します。

insertSlidesFromBase64(base64File: string, options?: PowerPoint.InsertSlideOptions): void;

パラメーター

base64File

string

ソース プレゼンテーション ファイルを表す Base64 エンコード文字列。

options
PowerPoint.InsertSlideOptions

挿入されるスライド、新しいスライドが表示される場所、および使用するプレゼンテーションの書式を定義するオプション。

返品

void

注釈

API セット: PowerPointApi 1.2

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

await PowerPoint.run(async function(context) {
    // Get the ID of the first selected slide.
    const presentation: PowerPoint.Presentation = context.presentation;
    const selected: PowerPoint.Slide = presentation.getSelectedSlides().getItemAt(0);
    selected.load("id");
    await context.sync();

    // Insert the other presentation after the selected slide.
    const insertOptions: PowerPoint.InsertSlideOptions = {
        formatting: PowerPoint.InsertSlideFormatting.useDestinationTheme,
        targetSlideId: selected.id
    };
    presentation.insertSlidesFromBase64(chosenFileBase64, insertOptions);
    await context.sync();
});

load(options)

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

load(options?: PowerPoint.Interfaces.PresentationLoadOptions): PowerPoint.Presentation;

パラメーター

options
PowerPoint.Interfaces.PresentationLoadOptions

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

返品

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

返品

load(propertyNamesAndPaths)

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

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

パラメーター

propertyNamesAndPaths

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

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

返品

setSelectedSlides(slideIds)

プレゼンテーションの現在のビューでスライドを選びます。 既存のスライド選択範囲は、新しい選択範囲に置き換えられます。

setSelectedSlides(slideIds: string[]): void;

パラメーター

slideIds

string[]

プレゼンテーションで選択するスライド ID の一覧。 一覧が空の場合は、選択はクリアされます。

返品

void

注釈

API セット: PowerPointApi 1.5

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

// Sets selection to the slides that were saved.
await PowerPoint.run(async (context) => {
  context.presentation.setSelectedSlides(savedSlideSelection);
  await context.sync();
});

...

// Selects slides 2, 4, and 5.
await PowerPoint.run(async (context) => {
  context.presentation.load("slides");
  await context.sync();
  const slide2: PowerPoint.Slide = context.presentation.slides.getItemAt(1);
  const slide4: PowerPoint.Slide = context.presentation.slides.getItemAt(3);
  const slide5: PowerPoint.Slide = context.presentation.slides.getItemAt(4);
  slide2.load("id");
  slide4.load("id");
  slide5.load("id");
  try {
    await context.sync();
  } catch (error) {
    console.warn("This action requires at least 5 slides in the presentation.");
    return;
  }
  await context.sync();
  context.presentation.setSelectedSlides([slide2.id, slide4.id, slide5.id]);
  await context.sync();
});

toJSON()

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

toJSON(): PowerPoint.Interfaces.PresentationData;

返品

イベントの詳細

onSlideSelectionChanged

注意

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

プレゼンテーションのスライドの選択が変更されたときに発生します。 このイベントは、ユーザーが別のスライドを選択したとき、またはスライドの選択を変更したときに発生します。 スライド内のコンテンツ (図形など) の選択が変更された場合、このイベントは発生しません。

readonly onSlideSelectionChanged: OfficeExtension.EventHandlers<PowerPoint.SlideSelectionChangedEventArgs>;

イベントの種類

注釈

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