Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
21d5313
added c# code
mkaszewiak Apr 3, 2025
458cc69
added vb code
mkaszewiak Apr 3, 2025
469c7bf
completed how to
mkaszewiak Apr 6, 2025
29b01f4
reverted unwanted changes
mkaszewiak Apr 6, 2025
fb4eb32
Update Program.cs
mkaszewiak Apr 6, 2025
b7b39d3
Update Program.vb
mkaszewiak Apr 6, 2025
2bb241b
Update add_transition_vb.vbproj
mkaszewiak Apr 6, 2025
d640c67
Update add_transition_cs.csproj
mkaszewiak Apr 6, 2025
5b7e978
fixed warnings
mkaszewiak Apr 7, 2025
d7e1138
fixed warning
mkaszewiak Apr 7, 2025
9523230
Merge branch 'main' into addTransitionToTheSlide
mkaszewiak May 12, 2025
ba3dd72
Add audio (#335)
mkaszewiak May 12, 2025
66a1466
Added MoveFrom/MoveTo code (#332)
mkaszewiak May 12, 2025
5f0c0e1
add new samples to toc.yml (#339)
mikeebowen May 12, 2025
46072f4
updated toc.yml and overview.md files
mkaszewiak May 13, 2025
1f1ec9c
Merge branch 'main' into addTransitionToTheSlide
mkaszewiak May 13, 2025
9ae8728
fixing file path typo in overview.md
mkaszewiak May 13, 2025
d1f321c
updated and sorted overview lists
mkaszewiak May 13, 2025
d757a68
Update docs/toc.yml
mkaszewiak May 13, 2025
fa8ce02
changed var to types
mkaszewiak May 14, 2025
5b3abb8
added instructions to update toc and overview
mkaszewiak May 14, 2025
f1f74eb
Add video (#334)
mkaszewiak May 14, 2025
7f810ea
Merge branch 'main' into updateOverviewFile
lindalu-MSFT May 22, 2025
17d5477
Merge pull request #341 from mkaszewiak/updateOverviewFile
lindalu-MSFT May 22, 2025
46f6b5c
Merge branch 'main' into addTransitionToTheSlide
lindalu-MSFT May 22, 2025
f3ed347
Merge pull request #338 from mkaszewiak/addTransitionToTheSlide
tomjebo May 22, 2025
11f69a1
Merge branch 'live' into main
lindalu-MSFT May 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions docs/presentation/how-to-add-a-video-to-a-slide-in-a-presentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---

api_name:
- Microsoft.Office.DocumentFormat.OpenXML.Packaging
api_type:
- schema
ms.assetid: 536c94b5-dd25-4173-ad6a-b72b95dd7f31
title: 'How to: Add a video to a slide in a presentation'
ms.suite: office

ms.author: o365devx
author: o365devx
ms.topic: conceptual
ms.date: 04/03/2025
ms.localizationpriority: medium
---

# Add a video to a slide in a presentation

This topic shows how to use the classes in the Open XML SDK for
Office to add a video to the first slide in a presentation
programmatically.

## Getting a Presentation Object

In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class represents a
presentation document package. To work with a presentation document,
first create an instance of the **PresentationDocument** class, and then work with
that instance. To create the class instance from the document call the
<xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Open*> method that uses a file path, and a
Boolean value as the second parameter to specify whether a document is
editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following
`using` statement. In this code, the file
parameter is a string that represents the path for the file from which
you want to open the document.

### [C#](#tab/cs-1)
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet1)]

### [Visual Basic](#tab/vb-1)
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet1)]
***


[!include[Using Statement](../includes/presentation/using-statement.md)] `ppt`.


## The Structure of the Video From File

The PresentationML document consists of a number of parts, among which is the Picture (`<pic/>`) element.

The following text from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification introduces the overall form of a `PresentationML` package.

Video File (`<videoFile/>`) specifies the presence of a video file. It is defined within the non-visual properties of an object. The video shall be attached to an object as this is how it is represented within the document. The actual playing of the video however is done within the timing node list that is specified under the timing element.

Consider the following `Picture` object that has a video attached to it.

```xml
<p:pic>
<p:nvPicPr>
<p:cNvPr id="7" name="Rectangle 6">
<a:hlinkClick r:id="" action="ppaction://media"/>
</p:cNvPr>
<p:cNvPicPr>
<a:picLocks noRot="1"/>
</p:cNvPicPr>
<p:nvPr>
<a:videoFile r:link="rId1"/>
</p:nvPr>
</p:nvPicPr>
</p:pic>
```

In the above example, we see that there is a single videoFile element attached to this picture. This picture is placed within the document just as a normal picture or shape would be. The id of this picture, namely 7 in this case, is used to refer to this videoFile element from within the timing node list. The Linked relationship id is used to retrieve the actual video file for playback purposes.

&copy; [!include[ISO/IEC 29500 version](../includes/iso-iec-29500-version.md)]

The following XML Schema fragment defines the contents of videoFile.

```xml
<xsd:complexType name="CT_TLMediaNodeVideo">
<xsd:sequence>
<xsd:element name="cMediaNode" type="CT_TLCommonMediaNodeData" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="fullScrn" type="xsd:boolean" use="optional" default="false"/>
</xsd:complexType>
```

## How the Sample Code Works

After opening the presentation file for read/write access in the `using` statement, the code gets the presentation
part from the presentation document. Then it gets the relationship ID of
the last slide, and gets the slide part from the relationship ID.


### [C#](#tab/cs-2)
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet2)]

### [Visual Basic](#tab/vb-2)
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet2)]
***

The code first creates a media data part for the video file to be added. With the video file stream open, it feeds the media data part object. Next, video and media relationship references are added to the slide using the provided embedId for future reference to the video file and mediaEmbedId for media reference.

An image part is then added with a sample picture to be used as a placeholder for the video. A picture object is created with various elements, such as Non-Visual Drawing Properties (`<cNvPr/>`), which specify non-visual canvas properties. This allows for additional information that does not affect the appearance of the picture to be stored. The `<videoFile/>` element, explained above, is also included. The HyperLinkOnClick (`<hlinkClick/>`) element specifies the on-click hyperlink information to be applied to a run of text or image. When the hyperlink text or image is clicked, the link is fetched. Non-Visual Picture Drawing Properties (`<cNvPicPr/>`) specify the non-visual properties for the picture canvas. For a detailed explanation of the elements used, please refer to [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)]

### [C#](#tab/cs-3)
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet3)]

### [Visual Basic](#tab/vb-3)
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet3)]
***

Next Media(CT_Media) element is created with use of previously referenced mediaEmbedId(Embedded Picture Reference). The Blip element is also added; this element specifies the existence of an image (binary large image or picture) and contains a reference to the image data. Blip's Embed attribute is used to specify a placeholder image in the Image Part created previously.

### [C#](#tab/cs-4)
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet4)]

### [Visual Basic](#tab/vb-4)
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet4)]
***

All other elements such Offset(`<off/>`), Stretch(`<stretch/>`), FillRectangle(`<fillRect/>`), are appended to the ShapeProperties(`<spPr/>`) and ShapeProperties are appended to the Picture element(`<pic/>`). Finally the picture element that incudes video is added to the ShapeTree(`<sp/>`) of the slide.

Following is the complete sample code that you can use to add video to the slide.

## Sample Code

### [C#](#tab/cs)
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet0)]

### [Visual Basic](#tab/vb)
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet0)]
***

## See also

- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---

api_name:
- Microsoft.Office.DocumentFormat.OpenXML.Packaging
api_type:
- schema
ms.assetid: 5471f369-ad02-41c3-a5d3-ebaf618d185a
title: 'How to: Add transitions between slides in a presentation'
ms.suite: office

ms.author: o365devx
author: o365devx
ms.topic: conceptual
ms.date: 04/03/2025
ms.localizationpriority: medium
---

# Add Transitions between slides in a presentation

This topic shows how to use the classes in the Open XML SDK to
add transition between all slides in a presentation programmatically.

## Getting a Presentation Object

In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class represents a
presentation document package. To work with a presentation document,
first create an instance of the `PresentationDocument` class, and then work with
that instance. To create the class instance from the document, call the
<xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Open*> method, that uses a file path, and a
Boolean value as the second parameter to specify whether a document is
editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following
`using` statement. In this code, the file parameter, is a string that represents the path for the file from which you want to open the document.

### [C#](#tab/cs-1)
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet1)]

### [Visual Basic](#tab/vb-1)
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet1)]
***

[!include[Using Statement](../includes/presentation/using-statement.md)] `ppt`.

## The Structure of the Transition

Transition element `<transition>` specifies the kind of slide transition that should be used to transition to the current slide from the
previous slide. That is, the transition information is stored on the slide that appears after the transition is
complete.

The following table lists the attributes of the Transition along
with the description of each.

| Attribute | Description |
|---|---|
| advClick (Advance on Click) | Specifies whether a mouse click advances the slide or not. If this attribute is not specified then a value of true is assumed. |
| advTm (Advance after time) | Specifies the time, in milliseconds, after which the transition should start. This setting can be used in conjunction with the advClick attribute. If this attribute is not specified then it is assumed that no auto-advance occurs. |
| spd (Transition Speed) |Specifies the transition speed that is to be used when transitioning from the current slide to the next. |

[*Example*: Consider the following example

```xml
<p:transition spd="slow" advClick="1" advTm="3000">
<p:randomBar dir="horz"/>
</p:transition>
```
In the above example, the transition speed `<speed>` is set to slow (available options: slow, med, fast). Advance on Click `<advClick>` is set to true, and Advance after time `<advTm>` is set to 3000 milliseconds. The Random Bar child element `<randomBar>` describes the randomBar slide transition effect, which uses a set of randomly placed horizontal `<dir="horz">` or vertical `<dir="vert">` bars on the slide that continue to be added until the new slide is fully shown. *end example*]

A full list of Transition's child elements can be viewed here: <xref:DocumentFormat.OpenXml.Presentation.Transition>

## The Structure of the Alternate Content

Office Open XML defines a mechanism for the storage of content that is not defined by the ISO/IEC 29500 Office Open XML specification, such as extensions developed by future software applications that leverage the Office Open XML formats. This mechanism allows for the storage of a series of alternative representations of content, from which the consuming application can use the first alternative whose requirements are met.

Consider an application that creates a new transition object intended to specify the duration of the transition. This functionality is not defined in the Office Open XML specification. Using an AlternateContent block as follows allows specifying the duration `<p14:dur>` in milliseconds.

[*Example*:
```xml
<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main">
<mc:Choice Requires="p14">
<p:transition spd="slow" p14:dur="2000" advClick="1" advTm="3000">
<p:randomBar/>
</p:transition>
</mc:Choice>
<mc:Fallback>
<p:transition spd="slow" advClick="1" advTm="3000">
<p:randomBar/>
</p:transition>
</mc:Fallback>
</mc:AlternateContent>
```

The Choice element in the above example requires the <xref:DocumentFormat.OpenXml.Linq.P14.dur*> attribute to specify the duration of the transition, and the Fallback element allows clients that do not support this namespace to see an appropriate alternative representation. *end example*]

More details on the P14 class can be found here: <xref:DocumentFormat.OpenXml.Linq.P14>

## How the Sample Code Works ##
After opening the presentation file for read/write access in the using statement, the code gets the presentation part from the presentation document. Then, it retrieves the relationship IDs of all slides in the presentation and gets the slides part from the relationship ID. The code then checks if there are no existing transitions set on the slides and replaces them with a new RandomBarTransition.

### [C#](#tab/cs-2)
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet2)]

### [Visual Basic](#tab/vb-2)
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet2)]
***

If there are currently no transitions on the slide, code creates new transition. In both cases as a fallback transition,
RandomBarTransition is used but without `P14:dur`(duration) to allow grater support for clients that aren't supporting this namespace

### [C#](#tab/cs-3)
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet3)]

### [Visual Basic](#tab/vb-3)
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet3)]
***

## Sample Code

Following is the complete sample code that you can use to add RandomBarTransition to all slides.

### [C#](#tab/cs)
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet0)]

### [Visual Basic](#tab/vb)
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet0)]
***

## See also

- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)




13 changes: 9 additions & 4 deletions docs/presentation/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ This section provides how-to topics for working with presentation documents usin

## In this section

- [Structure of a PresentationML document](structure-of-a-presentationml-document.md)
- [Structure of a PresentationML document](structure-of-a-presentationml-document.md)


- [Add an audio file to a slide in a presentation](how-to-add-an-audio-to-a-slide-in-a-presentation.md)

- [Add a comment to a slide in a presentation](how-to-add-a-comment-to-a-slide-in-a-presentation.md)

- [Apply a theme to a presentation](how-to-apply-a-theme-to-a-presentation.md)
Expand All @@ -30,7 +33,7 @@ This section provides how-to topics for working with presentation documents usin

- [Create a presentation document by providing a file name](how-to-create-a-presentation-document-by-providing-a-file-name.md)

- [Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentatio.md)
- [Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentation.md)

- [Delete a slide from a presentation](how-to-delete-a-slide-from-a-presentation.md)

Expand All @@ -40,7 +43,7 @@ This section provides how-to topics for working with presentation documents usin

- [Get all the text in all slides in a presentation](how-to-get-all-the-text-in-all-slides-in-a-presentation.md)

- [Get the titles of all the slides in a presentation](how-to-get-the-titles-of-all-the-slides-in-a-presentation.md)
- [Get the titles of all the slides in a presentation](how-to-get-the-titles-of-all-the-slides-in-a-presentation.md)

- [Insert a new slide into a presentation](how-to-insert-a-new-slide-into-a-presentation.md)

Expand All @@ -50,7 +53,9 @@ This section provides how-to topics for working with presentation documents usin

- [Open a presentation document for read-only access](how-to-open-a-presentation-document-for-read-only-access.md)

- [Retrieve the number of slides in a presentation document](how-to-retrieve-the-number-of-slides-in-a-presentation-document.md)
- [Retrieve the number of slides in a presentation document](how-to-retrieve-the-number-of-slides-in-a-presentation-document.md)

- [Add a transition to a slides in a presentation](how-to-add-transitions-between-slides-in-a-presentation.md)

- [Working with animation](working-with-animation.md)

Expand Down
2 changes: 1 addition & 1 deletion docs/presentation/working-with-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ article.
[About the Open XML SDK for Office](../about-the-open-xml-sdk.md)
[How to: Create a Presentation by Providing a File Name](how-to-create-a-presentation-document-by-providing-a-file-name.md)
[How to: Add a comment to a slide in a presentation](how-to-add-a-comment-to-a-slide-in-a-presentation.md)
[How to: Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentatio.md)
[How to: Delete all the comments by an author from all the slides in a presentation](how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentation.md)
31 changes: 18 additions & 13 deletions docs/spreadsheet/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,12 @@ This section provides how-to topics for working with spreadsheet documents using

- [Structure of a SpreadsheetML document](structure-of-a-spreadsheetml-document.md)

- [Working with the calculation chain](working-with-the-calculation-chain.md)

- [Working with conditional formatting](working-with-conditional-formatting.md)

- [Working with formulas](working-with-formulas.md)

- [Working with PivotTables](working-with-pivottables.md)

- [Working with the shared string table](working-with-the-shared-string-table.md)

- [Working with sheets](working-with-sheets.md)

- [Working with SpreadsheetML tables](working-with-tables.md)
- [Add custom UI to a spreadsheet document](how-to-add-custom-ui-to-a-spreadsheet-document.md)

- [Calculate the sum of a range of cells in a spreadsheet document](how-to-calculate-the-sum-of-a-range-of-cells-in-a-spreadsheet-document.md)

- [Copy a Worksheet Using SAX (Simple API for XML)](how-to-copy-a-worksheet-with-sax.md)

- [Create a spreadsheet document by providing a file name](how-to-create-a-spreadsheet-document-by-providing-a-file-name.md)

- [Delete text from a cell in a spreadsheet document](how-to-delete-text-from-a-cell-in-a-spreadsheet.md)
Expand Down Expand Up @@ -69,6 +59,21 @@ This section provides how-to topics for working with spreadsheet documents using

- [Retrieve the values of cells in a spreadsheet document](how-to-retrieve-the-values-of-cells-in-a-spreadsheet.md)

- [Retrieve a list of the worksheets in a spreadsheet document](how-to-retrieve-a-list-of-the-worksheets-in-a-spreadsheet.md)

- [Working with the calculation chain](working-with-the-calculation-chain.md)

- [Working with conditional formatting](working-with-conditional-formatting.md)

- [Working with formulas](working-with-formulas.md)

- [Working with PivotTables](working-with-pivottables.md)

- [Working with the shared string table](working-with-the-shared-string-table.md)

- [Working with sheets](working-with-sheets.md)

- [Working with SpreadsheetML tables](working-with-tables.md)

## Related sections

Expand Down
Loading