Cómo gestionar diapositivas en PowerPoint usando C# | IronPPT

Cómo administrar diapositivas en PowerPoint usando C

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

Una diapositiva es una sola página o pantalla en una presentación. Sirve como el bloque de construcción fundamental para organizar y mostrar contenido. Las diapositivas se utilizan para transmitir información visualmente y pueden incluir texto, imágenes, gráficos, tablas, videos, audio, animaciones y otros elementos de diseño.

Inicio rápido: Elimine, reordene o oculte fácilmente una diapositiva usando IronPPT

Aquí tienes un ejemplo de una línea que muestra cómo eliminar la primera diapositiva justo después de agregarla. IronPPT hace que las acciones comunes como gestionar diapositivas sean sencillas para los desarrolladores, para que puedas centrarte en el contenido en lugar de en las herramientas.

Nuget IconEmpieza a crear PDF con NuGet ahora:

  1. Instalar IronPPT con el gestor de paquetes NuGet

    PM > Install-Package IronPPT

  2. Copie y ejecute este fragmento de código.

    new PresentationDocument().AddSlide().Slides[0].Remove();
  3. Despliegue para probar en su entorno real

    Empieza a utilizar IronPPT en tu proyecto hoy mismo con una prueba gratuita
    arrow pointer

Agregar diapositiva

Agrega fácilmente una nueva diapositiva a la presentación usando el método AddSlide. Las nuevas diapositivas se añaden al final de la lista de diapositivas actual, permitiéndote expandir tu presentación sin problemas.

: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

Quitar diapositiva

Elimina las diapositivas no deseadas usando el método Remove. Esta función garantiza que puedas refinar rápidamente tu contenido y eliminar diapositivas innecesarias sin interrumpir la estructura general.

Por favor notaTodas las posiciones de índice de diapositivas siguen una indexación basada en cero.

: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

Reordenar diapositiva

Reorganiza el orden de las diapositivas para adaptarse mejor al flujo de tu presentación. Reordenar diapositivas es simple y eficiente, lo que facilita actualizar la secuencia de ideas o adaptarse a nuevos requisitos.

: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

Ocultar diapositiva

Oculta diapositivas específicas mientras las mantienes en la presentación. Las diapositivas ocultas no se muestran durante la presentación de diapositivas, pero permanecen accesibles para su edición o uso en presentaciones futuras.

: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
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 3,325 | Version: 2025.11 recién lanzado