You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to use PowerPoint add-ins to build engaging solutions for presentations across platforms including Windows, iPad, Mac, and in a browser.
4
-
ms.date: 10/16/2024
4
+
ms.date: 06/05/2025
5
5
ms.topic: overview
6
6
ms.custom: scenarios:getting-started
7
7
ms.localizationpriority: high
@@ -11,128 +11,98 @@ ms.localizationpriority: high
11
11
12
12
You can use PowerPoint add-ins to build engaging solutions for your users' presentations across platforms including Windows, iPad, Mac, and in a browser. You can create two types of PowerPoint add-ins:
13
13
14
-
- Use **content add-ins** to add dynamic HTML5 content to your presentations. For example, see the [LucidChart Diagrams for PowerPoint](https://appsource.microsoft.com/product/office/wa104380117) add-in, which you can use to inject an interactive diagram from LucidChart into your deck. To create your own content add-in, you can start with [Build your first PowerPoint content add-in](../quickstarts/powerpoint-quickstart-content.md).
15
-
16
14
- Use **task pane add-ins** to bring in reference information or insert data into the presentation via a service. For example, see the [Pexels - Free Stock Photos](https://appsource.microsoft.com/product/office/wa104379997) add-in, which you can use to add professional photos to your presentation. To create your own task pane add-in, you can start with [Build your first PowerPoint task pane add-in](../quickstarts/powerpoint-quickstart-yo.md).
17
15
18
-
## PowerPoint add-in scenarios
19
-
20
-
The code examples in this article demonstrate some basic tasks for developing add-ins for PowerPoint. Please note the following:
21
-
22
-
- To display information, these examples use the `app.showNotification` function, which is included in the Visual Studio Office Add-ins project templates. If you aren't using Visual Studio to develop your add-in, you'll need replace the `showNotification` function with your own code.
23
-
24
-
- Several of these examples also use a `Globals` object that's declared beyond the scope of these functions as:
- To use these examples, your add-in project must [reference Office.js v1.1 library or later](../develop/referencing-the-javascript-api-for-office-library-from-its-cdn.md).
29
-
30
-
## Detect the presentation's active view and handle the ActiveViewChanged event
16
+
- Use **content add-ins** to add dynamic HTML5 content to your presentations. For example, see the [LucidChart Diagrams for PowerPoint](https://appsource.microsoft.com/product/office/wa104380117) add-in, which injects interactive diagrams from LucidChart into your deck. To create your own content add-in, start with [Build your first PowerPoint content add-in](../quickstarts/powerpoint-quickstart-content.md).
31
17
32
-
If you're building a content add-in, you'll need to get the presentation's active view and handle the `ActiveViewChanged` event, as part of your `Office.onReady` handler.
33
-
34
-
> [!NOTE]
35
-
> In PowerPoint on the web, the [Document.ActiveViewChanged](/javascript/api/office/office.document) event will never fire as Slide Show mode is treated as a new session. In this case, the add-in must fetch the active view on load, as shown in the following code sample.
18
+
## PowerPoint add-in scenarios
36
19
37
-
Note the following about the code sample:
20
+
The code examples in this article demonstrate some basic tasks that can be useful when developing add-ins for PowerPoint.
38
21
39
-
- The `getActiveFileView` function calls the [Document.getActiveViewAsync](/javascript/api/office/office.document#office-office-document-getactiveviewasync-member(1)) method to return whether the presentation's current view is "edit" (any of the views in which you can edit slides, such as **Normal** or **Outline View**) or "read" (**Slide Show** or **Reading View**).
22
+
## Add a new slide then navigate to it
40
23
41
-
- The `registerActiveViewChanged` function calls the [addHandlerAsync](/javascript/api/office/office.document#office-office-document-addhandlerasync-member(1)) method to register a handler for the [Document.ActiveViewChanged](/javascript/api/office/office.document) event.
24
+
In the following code sample, the `addAndNavigateToNewSlide` function calls the [SlideCollection.add](/javascript/api/powerpoint/powerpoint.slidecollection#powerpoint-powerpoint-slidecollection-add-member(1)) method to add a new slide to the presentation. The function then calls the [Presentation.setSelectedSlides](/javascript/api/powerpoint/powerpoint.presentation#powerpoint-powerpoint-presentation-setselectedslides-member(1)) method to navigate to the new slide.
42
25
43
26
```js
44
-
// General Office.onReady function. Called after the add-in loads and Office JS is initialized.
45
-
Office.onReady(function() {
46
-
// Get whether the current view is edit or read.
47
-
constcurrentView=getActiveFileView();
48
-
49
-
// Register for the active view changed handler.
50
-
registerActiveViewChanged();
51
-
52
-
// Render the content based off of the currentView.
## Navigate to a particular slide in the presentation
85
48
86
-
In the following code sample, the `getSelectedRange` function calls the [Document.getSelectedDataAsync](/javascript/api/office/office.document#office-office-document-getselecteddataasync-member(1)) method to get the JSON object returned by `asyncResult.value`, which contains an array named `slides`. The `slides` array contains the IDs, titles, and indexes of selected range of slides (or of the current slide, if multiple slides aren't selected). It also saves the ID of the first slide in the selected range to a global variable.
49
+
In the following code sample, the `getSelectedSlides` function calls the [Presentation.getSelectedSlides](/javascript/api/powerpoint/powerpoint.presentation#powerpoint-powerpoint-presentation-getselectedslides-member(1)) method to get the selected slides then logs their IDs. The function can then act on the current slide (or first slide from the selection).
87
50
88
51
```js
89
-
functiongetSelectedRange() {
90
-
// Gets the ID, title, and index of the current slide (or selected slides) and store the first slide ID. */
91
-
Globals.firstSlideId=0;
92
-
93
-
Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function (asyncResult) {
94
-
if (asyncResult.status===Office.AsyncResultStatus.Failed) {
95
-
app.showNotification("Action failed with error: "+asyncResult.error.message);
In the following code sample, the `goToFirstSlide` function calls the [Document.goToByIdAsync](/javascript/api/office/office.document#office-office-document-gotobyidasync-member(1)) method to navigate to the first slide that was identified by the `getSelectedRange` function shown previously.
69
+
// Navigate to first selected slide.
70
+
constcurrentSlide=selectedSlides.items[0];
71
+
console.log(`Navigating to slide with ID ${currentSlide.id} ...`);
Office.context.document.goToByIdAsync(Globals.firstSlideId, Office.GoToType.Slide, function (asyncResult) {
109
-
if (asyncResult.status===Office.AsyncResultStatus.Failed) {
110
-
app.showNotification("Action failed with error: "+asyncResult.error.message);
111
-
} else {
112
-
app.showNotification("Navigation successful");
113
-
}
114
-
});
74
+
// Perform actions on current slide...
75
+
});
115
76
}
116
77
```
117
78
118
79
## Navigate between slides in the presentation
119
80
120
-
In the following code sample, the `goToSlideByIndex` function calls the `Document.goToByIdAsync` method to navigate to the next slide in the presentation.
81
+
In the following code sample, the `goToSlideByIndex` function calls the `Presentation.setSelectedSlides` method to navigate to the first slide in the presentation, which has the index 0. The maximum slide index you can navigate to in this sample is `slideCountResult.value - 1`.
121
82
122
83
```js
123
-
functiongoToSlideByIndex() {
124
-
constgoToFirst=Office.Index.First;
125
-
constgoToLast=Office.Index.Last;
126
-
constgoToPrevious=Office.Index.Previous;
127
-
constgoToNext=Office.Index.Next;
128
-
129
-
Office.context.document.goToByIdAsync(goToNext, Office.GoToType.Index, function (asyncResult) {
130
-
if (asyncResult.status===Office.AsyncResultStatus.Failed) {
131
-
app.showNotification("Action failed with error: "+asyncResult.error.message);
The `createPresentation` method can also create a copy of an existing presentation. The method accepts a Base64-encoded string representation of an .pptx file as an optional parameter. The resulting presentation will be a copy of that file, assuming the string argument is a valid .pptx file. The [FileReader](https://developer.mozilla.org/docs/Web/API/FileReader) class can be used to convert a file into the required Base64-encoded string, as demonstrated in the following example.
166
136
167
137
```js
168
-
constmyFile=document.getElementById("file");
138
+
constmyFile=document.getElementById("file") as HTMLInputElement;
169
139
constreader=newFileReader();
170
140
171
141
reader.onload=function (event) {
@@ -180,6 +150,8 @@ reader.onload = function (event) {
180
150
reader.readAsDataURL(myFile.files[0]);
181
151
```
182
152
153
+
To see a full code sample that includes an HTML implementation, see [Create presentation](https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/document/create-presentation.yaml).
-[How to save add-in state and settings per document for content and task pane add-ins](../develop/persisting-add-in-state-and-settings.md#how-to-save-add-in-state-and-settings-per-document-for-content-and-task-pane-add-ins)
192
164
-[Read and write data to the active selection in a document or spreadsheet](../develop/read-and-write-data-to-the-active-selection-in-a-document-or-spreadsheet.md)
193
-
-[Get the whole document from an add-in for PowerPoint or Word](../powerpoint/get-the-whole-document-from-an-add-in-for-powerpoint.md)
165
+
-[Get the whole document from an add-in for PowerPoint or Word](../develop/get-the-whole-document-from-an-add-in-for-powerpoint-or-word.md)
194
166
-[Use document themes in your PowerPoint add-ins](use-document-themes-in-your-powerpoint-add-ins.md)
0 commit comments