PowerPoint.Slide class

Represents a single slide of a presentation.

Extends

Remarks

[ API set: PowerPointApi 1.2 ]

Examples

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

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

id

Gets the unique ID of the slide.

layout

Gets the layout of the slide.

shapes

Returns a collection of shapes in the slide.

slideMaster

Gets the SlideMaster object that represents the slide's default content.

tags

Returns a collection of tags in the slide.

Methods

delete()

Deletes the slide from the presentation. Does nothing if the slide does not exist.

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

setSelectedShapes(shapeIds)

Selects the specified shapes. Existing shape selection is replaced with the new selection.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original PowerPoint.Slide object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.SlideData) that contains shallow copies of any loaded child properties from the original object.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

id

Gets the unique ID of the slide.

readonly id: string;

Property Value

string

Remarks

[ API set: PowerPointApi 1.2 ]

layout

Gets the layout of the slide.

readonly layout: PowerPoint.SlideLayout;

Property Value

Remarks

[ API set: PowerPointApi 1.3 ]

shapes

Returns a collection of shapes in the slide.

readonly shapes: PowerPoint.ShapeCollection;

Property Value

Remarks

[ API set: PowerPointApi 1.3 ]

slideMaster

Gets the SlideMaster object that represents the slide's default content.

readonly slideMaster: PowerPoint.SlideMaster;

Property Value

Remarks

[ API set: PowerPointApi 1.3 ]

tags

Returns a collection of tags in the slide.

readonly tags: PowerPoint.TagCollection;

Property Value

Remarks

[ API set: PowerPointApi 1.3 ]

Method Details

delete()

Deletes the slide from the presentation. Does nothing if the slide does not exist.

delete(): void;

Returns

void

Remarks

[ API set: PowerPointApi 1.2 ]

Examples

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

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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

Parameters

options
PowerPoint.Interfaces.SlideLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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

Parameters

propertyNamesAndPaths

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

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

setSelectedShapes(shapeIds)

Selects the specified shapes. Existing shape selection is replaced with the new selection.

setSelectedShapes(shapeIds: string[]): void;

Parameters

shapeIds

string[]

List of shape IDs to select in the slide. If the list is empty, the selection is cleared.

Returns

void

Remarks

[ API set: PowerPointApi 1.5 ]

Examples

// 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");
  await context.sync();
  const shapes: PowerPoint.ShapeCollection = slide1.shapes;
  const shape1: PowerPoint.Shape = shapes.getItemAt(0);
  const shape2: PowerPoint.Shape = shapes.getItemAt(1);
  shape1.load("id");
  shape2.load("id");
  await context.sync();
  slide1.setSelectedShapes([shape1.id, shape2.id]);
  await context.sync();
});

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original PowerPoint.Slide object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.SlideData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): PowerPoint.Interfaces.SlideData;

Returns