Skip to content

Commit

Permalink
closes OfficeDev#183
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeebowen committed Dec 31, 2024
1 parent 28c1ce3 commit f93643f
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 383 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ms.suite: office
ms.author: o365devx
author: o365devx
ms.topic: conceptual
ms.date: 06/28/2021
ms.date: 12/31/2024
ms.localizationpriority: high
---

Expand All @@ -35,64 +35,54 @@ presentation document contains, among other parts, a presentation part.
The presentation part, represented in the Open XML SDK by the <xref:DocumentFormat.OpenXml.Packaging.PresentationPart> class, contains the basic
*PresentationML* definition for the slide presentation. PresentationML
is the markup language used for creating presentations. Each package can
contain only one presentation part, and its root element must be
`<presentation/>`.
contain only one presentation part, and its root element must be `<presentation/>`.

The API calls used to create a new presentation document package are
relatively simple. The first step is to call the static [Create(String,PresentationDocumentType)](/dotnet/api/documentformat.openxml.packaging.presentationdocument.create)
relatively simple. The first step is to call the static <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Create*>
method of the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class, as shown here
in the **CreatePresentation** procedure, which is the first part of the
in the `CreatePresentation` procedure, which is the first part of the
complete code sample presented later in the article. The
**CreatePresentation** code calls the override of the **Create** method that takes as arguments the path to
`CreatePresentation` code calls the override of the `Create` method that takes as arguments the path to
the new document and the type of presentation document to be created.
The types of presentation documents available in that argument are
defined by a [PresentationDocumentType](/dotnet/api/documentformat.openxml.presentationdocumenttype) enumerated value.
defined by a <xref:DocumentFormat.OpenXml.PresentationDocumentType> enumerated value.

Next, the code calls [AddPresentationPart()](/dotnet/api/documentformat.openxml.packaging.presentationdocument.addpresentationpart), which creates and
returns a **PresentationPart**. After the **PresentationPart** class instance is created, a new
root element for the presentation is added by setting the [Presentation](/dotnet/api/documentformat.openxml.packaging.presentationpart.presentation) property equal to the instance
of the <xref:DocumentFormat.OpenXml.Presentation.Presentation> class returned from a call to
the **Presentation** class constructor.
Next, the code calls <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.AddPresentationPart*>, which creates and
returns a `PresentationPart`. After the `PresentationPart` class instance is created, a new
root element for the presentation is added by setting the <xref:DocumentFormat.OpenXml.Packaging.PresentationPart.Presentation*> property equal to the instance of the <xref:DocumentFormat.OpenXml.Presentation.Presentation> class returned from a call to
the `Presentation` class constructor.

In order to create a complete, useable, and valid presentation, the code
must also add a number of other parts to the presentation package. In
the example code, this is taken care of by a call to a utility function
named **CreatePresentationsParts**. That function then calls a number of
named `CreatePresentationsParts`. That function then calls a number of
other utility functions that, taken together, create all the
presentation parts needed for a basic presentation, including slide,
slide layout, slide master, and theme parts.

```csharp
public static void CreatePresentation(string filepath)
{
// Create a presentation at a specified file path. The presentation document type is pptx, by default.
PresentationDocument presentationDoc = PresentationDocument.Create(filepath, PresentationDocumentType.Presentation);
PresentationPart presentationPart = presentationDoc.AddPresentationPart();
presentationPart.Presentation = new Presentation();
### [C#](#tab/cs-1)
[!code-csharp[](../../samples/presentation/create_by_providing_a_file_name/cs/Program.cs#snippet1)]

CreatePresentationParts(presentationPart);

// Close the presentation handle
presentationDoc.Close();
}
```
### [Visual Basic](#tab/vb-1)
[!code-vb[](../../samples/presentation/create_by_providing_a_file_name/vb/Program.vb#snippet1)]
***

Using the Open XML SDK, you can create presentation structure and
content by using strongly-typed classes that correspond to
PresentationML elements. You can find these classes in the <a href="xref:DocumentFormat.OpenXml.Presentation?displayName=fullName" />
namespace. The following table lists the names of the classes that
correspond to the presentation, slide, slide master, slide layout, and
theme elements. The class that corresponds to the theme element is
actually part of the [DocumentFormat.OpenXml.Drawing](/dotnet/api/documentformat.openxml.drawing) namespace.
actually part of the <xref:DocumentFormat.OpenXml.Drawing> namespace.
Themes are common to all Open XML markup languages.

| PresentationML Element | Open XML SDK Class |
|---|---|
| &lt;presentation&gt; | <xref:DocumentFormat.OpenXml.Presentation.Presentation> |
| &lt;sld&gt; | <xref:DocumentFormat.OpenXml.Presentation.Slide> |
| &lt;sldMaster&gt; | <xref:DocumentFormat.OpenXml.Presentation.SlideMaster> |
| &lt;sldLayout&gt; | <xref:DocumentFormat.OpenXml.Presentation.SlideLayout> |
| &lt;theme&gt; | <xref:DocumentFormat.OpenXml.Drawing.Theme> |
| `<presentation/>` | <xref:DocumentFormat.OpenXml.Presentation.Presentation> |
| `<sld/>` | <xref:DocumentFormat.OpenXml.Presentation.Slide> |
| `<sldMaster/>` | <xref:DocumentFormat.OpenXml.Presentation.SlideMaster> |
| `<sldLayout/>` | <xref:DocumentFormat.OpenXml.Presentation.SlideLayout> |
| `<theme/>` | <xref:DocumentFormat.OpenXml.Drawing.Theme> |

The PresentationML code that follows is the XML in the presentation part
(in the file presentation.xml) for a simple presentation that contains
Expand Down Expand Up @@ -126,10 +116,11 @@ Following is the complete sample C\# and VB code to create a
presentation, given a file path.

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

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

--------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ms.suite: office
ms.author: o365devx
author: o365devx
ms.topic: conceptual
ms.date: 11/01/2017
ms.date: 12/31/2024
ms.localizationpriority: medium
---
# Delete a slide from a presentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@


CreatePresentation(args[0]);

// <Snippet0>
// <Snippet101>
// <Snippet1>
static void CreatePresentation(string filepath)
{
// Create a presentation at a specified file path. The presentation document type is pptx, by default.
Expand All @@ -21,6 +22,7 @@ static void CreatePresentation(string filepath)
//Dispose the presentation handle
presentationDoc.Dispose();
}
// </Snippet1>

static void CreatePresentationParts(PresentationPart presentationPart)
{
Expand Down Expand Up @@ -291,3 +293,4 @@ static ThemePart CreateTheme(SlideMasterPart slideMasterPart1)
return themePart1;

}
// </Snippet0>
Loading

0 comments on commit f93643f

Please sign in to comment.