Comment gérer les diapositives dans PowerPoint en utilisant C# | IronPPT

How to Manage Slides in PowerPoint

This article was translated from English: Does it need improvement?
Translated
View the article in English

Une diapositive est une page ou un écran unique dans une présentation. Il s'agit d'un élément fondamental pour l'organisation et l'affichage du contenu. Les diapositives sont utilisées pour transmettre des informations visuellement et peuvent inclure du texte, des images, des graphiques, des tableaux, des vidéos, du son, des animations et d'autres éléments de conception.

Quickstart : Easily remove, reorder, or hide a slide using IronPPT

Voici un exemple en une ligne montrant comment supprimer la première diapositive juste après l'avoir ajoutée. IronPPT rend les actions courantes telles que la gestion des diapositives sans effort pour les développeurs afin que vous puissiez vous concentrer sur le contenu plutôt que sur l'outillage.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPPT with NuGet Package Manager

    PM > Install-Package IronPPT

  2. Copy and run this code snippet.

    new PresentationDocument().AddSlide().Slides[0].Remove();
  3. Deploy to test on your live environment

    Start using IronPPT in your project today with a free trial
    arrow pointer

Ajouter une diapositive

Ajoutez facilement une nouvelle diapositive à la présentation à l'aide de la méthode AddSlide. Les nouvelles diapositives sont ajoutées à la fin de la liste de diapositives actuelle, ce qui vous permet d'étendre votre présentation de manière transparente.

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-add-slide.cs
// Ensure you have the necessary using directives for any external libraries or namespaces.
using IronPPT;

// Instantiate a new PresentationDocument object.
var document = new PresentationDocument();

// Add three slides to the presentation.
// The AddSlide method creates a new slide and adds it to the list of slides in the document.
document.AddSlide();  // Add first slide
document.AddSlide();  // Add second slide
document.AddSlide();  // Add third slide

// Save the presentation to a file named "addSlides.pptx".
// The Save method takes a file path as an argument and writes the current state of the presentation to this file.
document.Save("addSlides.pptx");
' Ensure you have the necessary using directives for any external libraries or namespaces.
Imports IronPPT

' Instantiate a new PresentationDocument object.
Private document = New PresentationDocument()

' Add three slides to the presentation.
' The AddSlide method creates a new slide and adds it to the list of slides in the document.
document.AddSlide() ' Add first slide
document.AddSlide() ' Add second slide
document.AddSlide() ' Add third slide

' Save the presentation to a file named "addSlides.pptx".
' The Save method takes a file path as an argument and writes the current state of the presentation to this file.
document.Save("addSlides.pptx")
$vbLabelText   $csharpLabel

Supprimer la diapositive

Supprimez les diapositives indésirables à l'aide de la méthode Remove. Cette fonction vous permet d'affiner rapidement votre contenu et de supprimer les diapositives inutiles sans perturber la structure générale.

[{i :(Toutes les positions de l'index des diapositives suivent l'indexation à base zéro.)}]

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-remove-slide.cs
// Import the IronPPT namespace to handle PowerPoint presentations
// Assuming IronPPT is a fictional or placeholder library. Substitute with actual library as needed
using IronPPT;

// Create a new instance of the PresentationDocument class, assuming PresentationDocument 
// is a part of IronPPT that helps create or modify PowerPoint presentations
var document = new PresentationDocument();

// Add a new slide to the presentation, assuming the Add method adds a new slide to the collection
document.Slides.Add(new Slide());

// Check if there is at least one slide before attempting to remove
if (document.Slides.Count > 0)
{
    // Remove the first slide from the presentation's list of slides
    document.Slides.RemoveAt(0);
}

// Save the modified presentation to a file named "removeSlide.pptx"
// The Save method will write the current state of the presentation to the specified file
document.Save("removeSlide.pptx");
' Import the IronPPT namespace to handle PowerPoint presentations
' Assuming IronPPT is a fictional or placeholder library. Substitute with actual library as needed
Imports IronPPT

' Create a new instance of the PresentationDocument class, assuming PresentationDocument 
' is a part of IronPPT that helps create or modify PowerPoint presentations
Private document = New PresentationDocument()

' Add a new slide to the presentation, assuming the Add method adds a new slide to the collection
document.Slides.Add(New Slide())

' Check if there is at least one slide before attempting to remove
If document.Slides.Count > 0 Then
	' Remove the first slide from the presentation's list of slides
	document.Slides.RemoveAt(0)
End If

' Save the modified presentation to a file named "removeSlide.pptx"
' The Save method will write the current state of the presentation to the specified file
document.Save("removeSlide.pptx")
$vbLabelText   $csharpLabel

Réorganiser la diapositive

Réorganisez l'ordre des diapositives pour qu'il corresponde mieux au déroulement de votre présentation. La réorganisation des diapositives est simple et efficace, ce qui facilite la mise à jour de l'ordre des idées ou l'adaptation à de nouvelles exigences.

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-reorder-slide.cs
using IronPPT;

var document = new PresentationDocument();

// Adding a new slide to the document.
document.AddSlide();

// To reorder slides, we must remove the slide from its current position 
// and then insert it back at the desired position. 

// Capture the slide to be moved. 
// Assuming we want to move the first slide in this case.
var slideToMove = document.Slides[0];

// Remove the slide from its current position.
document.Slides.Remove(slideToMove);

// Add the slide back at the desired index (for example, index 1).
// Ensure the desired index is valid and within the range of the current slides.
if (document.Slides.Count >= 1) // Check if there is at least one slide to insert into.
{
    document.Slides.Insert(1, slideToMove);
}

// Save the presentation with the reordered slide.
// Ensure a valid file path and name are provided.
document.Save("reorderSlide.pptx");
Imports IronPPT

Private document = New PresentationDocument()

' Adding a new slide to the document.
document.AddSlide()

' To reorder slides, we must remove the slide from its current position 
' and then insert it back at the desired position. 

' Capture the slide to be moved. 
' Assuming we want to move the first slide in this case.
Dim slideToMove = document.Slides(0)

' Remove the slide from its current position.
document.Slides.Remove(slideToMove)

' Add the slide back at the desired index (for example, index 1).
' Ensure the desired index is valid and within the range of the current slides.
If document.Slides.Count >= 1 Then ' Check if there is at least one slide to insert into.
	document.Slides.Insert(1, slideToMove)
End If

' Save the presentation with the reordered slide.
' Ensure a valid file path and name are provided.
document.Save("reorderSlide.pptx")
$vbLabelText   $csharpLabel

Cacher la diapositive

Masquez certaines diapositives tout en les conservant dans la présentation. Les diapositives cachées ne sont pas affichées pendant le diaporama, mais restent accessibles pour être modifiées ou utilisées dans des présentations ultérieures.

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-hide-slide.cs
using IronPPT;

// Create a new presentation document
var document = new PresentationDocument();

// Add a new slide to the presentation
document.AddSlide();

// Hide the first slide by setting its visibility to false
document.Slides[0].Visible = false;

// Save the presentation to a file named 'hideSlide.pptx'
document.Save("hideSlide.pptx");
Imports IronPPT

' Create a new presentation document
Private document = New PresentationDocument()

' Add a new slide to the presentation
document.AddSlide()

' Hide the first slide by setting its visibility to false
document.Slides(0).Visible = False

' Save the presentation to a file named 'hideSlide.pptx'
document.Save("hideSlide.pptx")
$vbLabelText   $csharpLabel
Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Nuget Téléchargements 3,171 | Version : 2025.11 vient de sortir