PowerPoint.Presentation class
Presentation オブジェクトは、プレゼンテーションの内容を含む 1 つ以上のスライドを含む最上位のオブジェクトです。 PowerPoint オブジェクト モデルの詳細については、「 JavaScript オブジェクト モデルのPowerPoint」を参照してください。
- Extends
注釈
[ API set: 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 ホスト アプリケーションのプロセスに接続されます。 |
| custom |
プレゼンテーションに関連付けられているカスタム XML パーツのコレクションを返します。 |
| id | プレゼンテーションの ID を取得します。 |
| page |
プロパティがプレゼンテーションのスライド設定属性を制御するページ設定情報を返します。 |
| properties | プレゼンテーションのプロパティを取得します。 |
| slide |
プレゼンテーション内にある |
| slides | プレゼンテーション内のスライドの順序付きコレクションを返します。 |
| tags | プレゼンテーションに添付されたタグのコレクションを返します。 |
| title | プレゼンテーションのタイトルを返します。 |
メソッド
| get |
編集領域に表示されている現在のアクティブな PowerPoint.Slide を返します。 アクティブなスライドがない場合は、 |
| get |
プレゼンテーションの現在のスライドで選択した図形を返します。 図形が選択されていない場合は、空のコレクションが返されます。 |
| get |
プレゼンテーションの現在のビューで選択したスライドを返します。 コレクションの最初の項目は、編集領域に表示されるアクティブなスライドです。 スライドが選択されていない場合は、空のコレクションが返されます。 |
| get |
プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は例外をスローします。 |
| get |
プレゼンテーションの現在のビューで選択した PowerPoint.TextRange を返します。 テキストが選択されていない場合は、 |
| insert |
プレゼンテーションから現在のプレゼンテーションに指定したスライドを挿入します。 |
| load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
| set |
プレゼンテーションの現在のビューでスライドを選択します。 既存のスライド選択は、新しい選択に置き換えられます。 |
| toJSON() | API オブジェクトが |
プロパティの詳細
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;
プロパティ値
注釈
id
pageSetup
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
プロパティがプレゼンテーションのスライド設定属性を制御するページ設定情報を返します。
readonly pageSetup: PowerPoint.PageSetup;
プロパティ値
注釈
properties
プレゼンテーションのプロパティを取得します。
readonly properties: PowerPoint.DocumentProperties;
プロパティ値
注釈
slideMasters
プレゼンテーション内にある SlideMaster オブジェクトのコレクションを返します。
readonly slideMasters: PowerPoint.SlideMasterCollection;
プロパティ値
注釈
slides
プレゼンテーション内のスライドの順序付きコレクションを返します。
readonly slides: PowerPoint.SlideCollection;
プロパティ値
注釈
tags
プレゼンテーションに添付されたタグのコレクションを返します。
readonly tags: PowerPoint.TagCollection;
プロパティ値
注釈
title
メソッドの詳細
getActiveSlideOrNullObject()
注意
この API は開発者向けにプレビューとして提供されており、寄せられたフィードバックにもとづいて変更される場合があります。 この API は運用環境で使用しないでください。
編集領域に表示されている現在のアクティブな PowerPoint.Slide を返します。 アクティブなスライドがない場合は、 isNullObject プロパティが true に設定されたオブジェクトが返されます。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
getActiveSlideOrNullObject(): PowerPoint.Slide;
戻り値
注釈
[ API セット: PowerPointApi BETA (プレビューのみ) ]
例
// 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;
戻り値
注釈
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;
パラメーター
読み込むオブジェクトのプロパティのオプションを提供します。
戻り値
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;