Skip to content

Commit cbc1470

Browse files
authored
Merge pull request #342 from OfficeDev/main
[admin] merge to live
2 parents 638c8fb + 11f69a1 commit cbc1470

18 files changed

+928
-25
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
3+
api_name:
4+
- Microsoft.Office.DocumentFormat.OpenXML.Packaging
5+
api_type:
6+
- schema
7+
ms.assetid: 536c94b5-dd25-4173-ad6a-b72b95dd7f31
8+
title: 'How to: Add a video to a slide in a presentation'
9+
ms.suite: office
10+
11+
ms.author: o365devx
12+
author: o365devx
13+
ms.topic: conceptual
14+
ms.date: 04/03/2025
15+
ms.localizationpriority: medium
16+
---
17+
18+
# Add a video to a slide in a presentation
19+
20+
This topic shows how to use the classes in the Open XML SDK for
21+
Office to add a video to the first slide in a presentation
22+
programmatically.
23+
24+
## Getting a Presentation Object
25+
26+
In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class represents a
27+
presentation document package. To work with a presentation document,
28+
first create an instance of the **PresentationDocument** class, and then work with
29+
that instance. To create the class instance from the document call the
30+
<xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Open*> method that uses a file path, and a
31+
Boolean value as the second parameter to specify whether a document is
32+
editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following
33+
`using` statement. In this code, the file
34+
parameter is a string that represents the path for the file from which
35+
you want to open the document.
36+
37+
### [C#](#tab/cs-1)
38+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet1)]
39+
40+
### [Visual Basic](#tab/vb-1)
41+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet1)]
42+
***
43+
44+
45+
[!include[Using Statement](../includes/presentation/using-statement.md)] `ppt`.
46+
47+
48+
## The Structure of the Video From File
49+
50+
The PresentationML document consists of a number of parts, among which is the Picture (`<pic/>`) element.
51+
52+
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.
53+
54+
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.
55+
56+
Consider the following `Picture` object that has a video attached to it.
57+
58+
```xml
59+
<p:pic>
60+
<p:nvPicPr>
61+
<p:cNvPr id="7" name="Rectangle 6">
62+
<a:hlinkClick r:id="" action="ppaction://media"/>
63+
</p:cNvPr>
64+
<p:cNvPicPr>
65+
<a:picLocks noRot="1"/>
66+
</p:cNvPicPr>
67+
<p:nvPr>
68+
<a:videoFile r:link="rId1"/>
69+
</p:nvPr>
70+
</p:nvPicPr>
71+
</p:pic>
72+
```
73+
74+
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.
75+
76+
&copy; [!include[ISO/IEC 29500 version](../includes/iso-iec-29500-version.md)]
77+
78+
The following XML Schema fragment defines the contents of videoFile.
79+
80+
```xml
81+
<xsd:complexType name="CT_TLMediaNodeVideo">
82+
<xsd:sequence>
83+
<xsd:element name="cMediaNode" type="CT_TLCommonMediaNodeData" minOccurs="1" maxOccurs="1"/>
84+
</xsd:sequence>
85+
<xsd:attribute name="fullScrn" type="xsd:boolean" use="optional" default="false"/>
86+
</xsd:complexType>
87+
```
88+
89+
## How the Sample Code Works
90+
91+
After opening the presentation file for read/write access in the `using` statement, the code gets the presentation
92+
part from the presentation document. Then it gets the relationship ID of
93+
the last slide, and gets the slide part from the relationship ID.
94+
95+
96+
### [C#](#tab/cs-2)
97+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet2)]
98+
99+
### [Visual Basic](#tab/vb-2)
100+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet2)]
101+
***
102+
103+
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.
104+
105+
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)]
106+
107+
### [C#](#tab/cs-3)
108+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet3)]
109+
110+
### [Visual Basic](#tab/vb-3)
111+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet3)]
112+
***
113+
114+
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.
115+
116+
### [C#](#tab/cs-4)
117+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet4)]
118+
119+
### [Visual Basic](#tab/vb-4)
120+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet4)]
121+
***
122+
123+
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.
124+
125+
Following is the complete sample code that you can use to add video to the slide.
126+
127+
## Sample Code
128+
129+
### [C#](#tab/cs)
130+
[!code-csharp[](../../samples/presentation/add_video/cs/Program.cs#snippet0)]
131+
132+
### [Visual Basic](#tab/vb)
133+
[!code-vb[](../../samples/presentation/add_video/vb/Program.vb#snippet0)]
134+
***
135+
136+
## See also
137+
138+
- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
3+
api_name:
4+
- Microsoft.Office.DocumentFormat.OpenXML.Packaging
5+
api_type:
6+
- schema
7+
ms.assetid: 5471f369-ad02-41c3-a5d3-ebaf618d185a
8+
title: 'How to: Add transitions between slides in a presentation'
9+
ms.suite: office
10+
11+
ms.author: o365devx
12+
author: o365devx
13+
ms.topic: conceptual
14+
ms.date: 04/03/2025
15+
ms.localizationpriority: medium
16+
---
17+
18+
# Add Transitions between slides in a presentation
19+
20+
This topic shows how to use the classes in the Open XML SDK to
21+
add transition between all slides in a presentation programmatically.
22+
23+
## Getting a Presentation Object
24+
25+
In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class represents a
26+
presentation document package. To work with a presentation document,
27+
first create an instance of the `PresentationDocument` class, and then work with
28+
that instance. To create the class instance from the document, call the
29+
<xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Open*> method, that uses a file path, and a
30+
Boolean value as the second parameter to specify whether a document is
31+
editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following
32+
`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.
33+
34+
### [C#](#tab/cs-1)
35+
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet1)]
36+
37+
### [Visual Basic](#tab/vb-1)
38+
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet1)]
39+
***
40+
41+
[!include[Using Statement](../includes/presentation/using-statement.md)] `ppt`.
42+
43+
## The Structure of the Transition
44+
45+
Transition element `<transition>` specifies the kind of slide transition that should be used to transition to the current slide from the
46+
previous slide. That is, the transition information is stored on the slide that appears after the transition is
47+
complete.
48+
49+
The following table lists the attributes of the Transition along
50+
with the description of each.
51+
52+
| Attribute | Description |
53+
|---|---|
54+
| 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. |
55+
| 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. |
56+
| spd (Transition Speed) |Specifies the transition speed that is to be used when transitioning from the current slide to the next. |
57+
58+
[*Example*: Consider the following example
59+
60+
```xml
61+
<p:transition spd="slow" advClick="1" advTm="3000">
62+
<p:randomBar dir="horz"/>
63+
</p:transition>
64+
```
65+
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*]
66+
67+
A full list of Transition's child elements can be viewed here: <xref:DocumentFormat.OpenXml.Presentation.Transition>
68+
69+
## The Structure of the Alternate Content
70+
71+
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.
72+
73+
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.
74+
75+
[*Example*:
76+
```xml
77+
<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
78+
xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main">
79+
<mc:Choice Requires="p14">
80+
<p:transition spd="slow" p14:dur="2000" advClick="1" advTm="3000">
81+
<p:randomBar/>
82+
</p:transition>
83+
</mc:Choice>
84+
<mc:Fallback>
85+
<p:transition spd="slow" advClick="1" advTm="3000">
86+
<p:randomBar/>
87+
</p:transition>
88+
</mc:Fallback>
89+
</mc:AlternateContent>
90+
```
91+
92+
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*]
93+
94+
More details on the P14 class can be found here: <xref:DocumentFormat.OpenXml.Linq.P14>
95+
96+
## How the Sample Code Works ##
97+
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.
98+
99+
### [C#](#tab/cs-2)
100+
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet2)]
101+
102+
### [Visual Basic](#tab/vb-2)
103+
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet2)]
104+
***
105+
106+
If there are currently no transitions on the slide, code creates new transition. In both cases as a fallback transition,
107+
RandomBarTransition is used but without `P14:dur`(duration) to allow grater support for clients that aren't supporting this namespace
108+
109+
### [C#](#tab/cs-3)
110+
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet3)]
111+
112+
### [Visual Basic](#tab/vb-3)
113+
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet3)]
114+
***
115+
116+
## Sample Code
117+
118+
Following is the complete sample code that you can use to add RandomBarTransition to all slides.
119+
120+
### [C#](#tab/cs)
121+
[!code-csharp[](../../samples/presentation/add_transition/cs/Program.cs#snippet0)]
122+
123+
### [Visual Basic](#tab/vb)
124+
[!code-vb[](../../samples/presentation/add_transition/vb/Program.vb#snippet0)]
125+
***
126+
127+
## See also
128+
129+
- [Open XML SDK class library reference](/office/open-xml/open-xml-sdk)
130+
131+
132+
133+

docs/presentation/how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentatio.md renamed to docs/presentation/how-to-delete-all-the-comments-by-an-author-from-all-the-slides-in-a-presentation.md

File renamed without changes.

docs/presentation/overview.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ This section provides how-to topics for working with presentation documents usin
2020

2121
## In this section
2222

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

25+
26+
- [Add an audio file to a slide in a presentation](how-to-add-an-audio-to-a-slide-in-a-presentation.md)
27+
2528
- [Add a comment to a slide in a presentation](how-to-add-a-comment-to-a-slide-in-a-presentation.md)
2629

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

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

33-
- [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)
36+
- [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)
3437

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

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

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

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

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

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

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

53-
- [Retrieve the number of slides in a presentation document](how-to-retrieve-the-number-of-slides-in-a-presentation-document.md)
56+
- [Retrieve the number of slides in a presentation document](how-to-retrieve-the-number-of-slides-in-a-presentation-document.md)
57+
58+
- [Add a transition to a slides in a presentation](how-to-add-transitions-between-slides-in-a-presentation.md)
5459

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

docs/presentation/working-with-comments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@ article.
193193
[About the Open XML SDK for Office](../about-the-open-xml-sdk.md)
194194
[How to: Create a Presentation by Providing a File Name](how-to-create-a-presentation-document-by-providing-a-file-name.md)
195195
[How to: Add a comment to a slide in a presentation](how-to-add-a-comment-to-a-slide-in-a-presentation.md)
196-
[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)
196+
[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)

docs/spreadsheet/overview.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,12 @@ This section provides how-to topics for working with spreadsheet documents using
2323

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

26-
- [Working with the calculation chain](working-with-the-calculation-chain.md)
27-
28-
- [Working with conditional formatting](working-with-conditional-formatting.md)
29-
30-
- [Working with formulas](working-with-formulas.md)
31-
32-
- [Working with PivotTables](working-with-pivottables.md)
33-
34-
- [Working with the shared string table](working-with-the-shared-string-table.md)
35-
36-
- [Working with sheets](working-with-sheets.md)
37-
38-
- [Working with SpreadsheetML tables](working-with-tables.md)
26+
- [Add custom UI to a spreadsheet document](how-to-add-custom-ui-to-a-spreadsheet-document.md)
3927

4028
- [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)
4129

30+
- [Copy a Worksheet Using SAX (Simple API for XML)](how-to-copy-a-worksheet-with-sax.md)
31+
4232
- [Create a spreadsheet document by providing a file name](how-to-create-a-spreadsheet-document-by-providing-a-file-name.md)
4333

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

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

62+
- [Retrieve a list of the worksheets in a spreadsheet document](how-to-retrieve-a-list-of-the-worksheets-in-a-spreadsheet.md)
63+
64+
- [Working with the calculation chain](working-with-the-calculation-chain.md)
65+
66+
- [Working with conditional formatting](working-with-conditional-formatting.md)
67+
68+
- [Working with formulas](working-with-formulas.md)
69+
70+
- [Working with PivotTables](working-with-pivottables.md)
71+
72+
- [Working with the shared string table](working-with-the-shared-string-table.md)
73+
74+
- [Working with sheets](working-with-sheets.md)
75+
76+
- [Working with SpreadsheetML tables](working-with-tables.md)
7277

7378
## Related sections
7479

0 commit comments

Comments
 (0)