PowerPoint.Presentation class

Extends

注釈

[ API set: PowerPointApi 1.0 ]

プロパティ

context

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

id

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

slideMasters

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

slides

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

tags

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

title

メソッド

getSelectedShapes()

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

getSelectedSlides()

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

getSelectedTextRange()

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

getSelectedTextRangeOrNullObject()

プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は、プロパティが isNullObjecttrue 設定されたオブジェクトが返されます。

insertSlidesFromBase64(base64File, options)

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

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

setSelectedSlides(slideIds)

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

toJSON()

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

プロパティの詳細

context

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

context: RequestContext;

プロパティ値

id

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

readonly id: string;

プロパティ値

string

注釈

[ API セット: PowerPointApi 1.5 ]

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

メソッドの詳細

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 = 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 = 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>";
  $("#outputSpan").empty();
  $("#outputSpan").append(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 = context.presentation.getSelectedSlides();
  const slideCount = slides.getCount();
  slides.load("items");
  await context.sync();
  savedSlideSelection = [];
  slides.items.map((slide) => {
    savedSlideSelection.push(slide.id);
  });
  const shapes = 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 = context.presentation.slides.items;
  allSlideItems.map((slide, index) => {
    allSlidesList[slide.id] = `Slide ${index + 1}`;
  });

  if ($("#id-check-usenative").is(":checked")) {
    context.presentation.load("tags");
  }
  const slides = 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>";
  $("#outputSpan").empty();
  $("#outputSpan").append(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 = 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>";
  $("#outputSpan").empty();
  $("#outputSpan").append(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 = 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 +=
    "<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>";
  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>";
  $("#outputSpan").empty();
  $("#outputSpan").append(finalTable);
});

...

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

getSelectedTextRangeOrNullObject()

プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は、プロパティが isNullObjecttrue 設定されたオブジェクトが返されます。

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) {
    const selectedSlideID = await getSelectedSlideID();

    context.presentation.insertSlidesFromBase64(chosenFileBase64, {
        formatting: PowerPoint.InsertSlideFormatting.useDestinationTheme,
        targetSlideId: selectedSlideID + "#"
    });
    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 = context.presentation.slides.getItemAt(1);
  const slide4 = context.presentation.slides.getItemAt(3);
  const slide5 = 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 オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出 toJSON します)。元の PowerPoint.Presentation オブジェクトは API オブジェクトですが、メソッドは、元の toJSON オブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (として PowerPoint.Interfaces.PresentationData型指定) を返します。

toJSON(): PowerPoint.Interfaces.PresentationData;

戻り値