Getting Started with IronPPT

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

IronPowerPoint : Bibliothèque PowerPoint pour .NET

IronPPT est une bibliothèque PowerPoint développée par Iron Software. Elle excelle dans la fourniture de fonctionnalités robustes pour travailler avec des présentations PowerPoint dans des applications .NET.

  • Charger, manipuler et enregistrer des présentations PowerPoint. Travaillez facilement avec les fichiers .pptx et .ppt.
  • SlideSetup : Permet de configurer la taille, l'orientation, la couleur d'arrière-plan et la mise en page des diapositives.
  • Texte : Gérer le contenu du texte, les styles, la division, l'ajout de texte et l'ajout de zones de texte.
  • TextStyle : Gérer la famille de polices, la taille, la couleur, le gras, l'italique, le soulignement et l'alignement.
  • Formes : Ajouter et manipuler des formes, notamment en définissant la taille, la position, le type et la rotation.
  • Images : Insérez des images dans les diapositives avec des options de mise à l'échelle, d'alignement et de positionnement.

Installation

La bibliothèque IronPPT

L'installation d'IronPPT est rapide et simple. Ajoutez le paquet à l'aide de la méthode suivante :

Install-Package IronPPT

Vous pouvez également la télécharger directement sur le site officiel NuGet d'IronPPT.

Après l'installation, il suffit d'inclure utilisant IronPPT; en haut de votre code C# pour commencer.

Application de la clé de licence

Pour utiliser IronPPT, appliquez une licence ou une clé d'essai valide en définissant la propriété LicenseKey. Ajoutez le code suivant immédiatement après l'instruction d'importation et avant d'appeler toute méthode IronPPT :

:path=/static-assets/ppt/content-code-examples/get-started/get-started-license.cs
/// <summary>
/// This code sets the license key for the IronPPT library.
/// Ensure you have the correct namespace access by installing the IronPPT NuGet package
/// and adjust the license key appropriately for your use case.
/// </summary>

using System; // Required for Console output
using IronPPT; // Ensure the IronPPT library is referenced in your project.

namespace IronPPTApplication
{
    class Program
    {
        public static void Main(string[] args)
        {
            // Calling the method to set the IronPPT license key.
            SetIronPPTLicense();
        }

        /// <summary>
        /// Sets the license key for the IronPPT library to unlock its full features.
        /// </summary>
        private static void SetIronPPTLicense()
        {
            // Correctly setting the license for the IronPPT library.
            // Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.
            IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01";

            // Inform the user that the license key has been set.
            Console.WriteLine("IronPPT license key has been set.");
        }
    }
}
''' <summary>
''' This code sets the license key for the IronPPT library.
''' Ensure you have the correct namespace access by installing the IronPPT NuGet package
''' and adjust the license key appropriately for your use case.
''' </summary>

Imports System ' Required for Console output
Imports IronPPT ' Ensure the IronPPT library is referenced in your project.

Namespace IronPPTApplication
	Friend Class Program
		Public Shared Sub Main(ByVal args() As String)
			' Calling the method to set the IronPPT license key.
			SetIronPPTLicense()
		End Sub

		''' <summary>
		''' Sets the license key for the IronPPT library to unlock its full features.
		''' </summary>
		Private Shared Sub SetIronPPTLicense()
			' Correctly setting the license for the IronPPT library.
			' Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.
			IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01"

			' Inform the user that the license key has been set.
			Console.WriteLine("IronPPT license key has been set.")
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

Exemples de code

Examinons quelques exemples de code et les fonctionnalités disponibles.

Créer un fichier PowerPoint

Créez la présentation PowerPoint en instanciant la classe PresentationDocument à l'aide de l'un de ses constructeurs. Utilisez les méthodes AddSlide et AddText pour ajouter des diapositives et du texte, respectivement. Ensuite, utilisez la méthode Save pour exporter la présentation PowerPoint.

:path=/static-assets/ppt/content-code-examples/get-started/get-started-1.cs
using IronPPT;

// This code demonstrates the creation of a PowerPoint presentation and saving it as a file.

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

// Create a new slide object
var slide = new Slide();

// Add text content to the slide
slide.AddText("Hello!");

// Add the newly created slide with text to the document
document.AddSlide(slide);

// Export the PowerPoint presentation to a file named "output.pptx"
document.Save("output.pptx");
Imports IronPPT

' This code demonstrates the creation of a PowerPoint presentation and saving it as a file.

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

' Create a new slide object
Private slide = New Slide()

' Add text content to the slide
slide.AddText("Hello!")

' Add the newly created slide with text to the document
document.AddSlide(slide)

' Export the PowerPoint presentation to a file named "output.pptx"
document.Save("output.pptx")
$vbLabelText   $csharpLabel

Ajouter une forme

Vous pouvez utiliser la méthode AddShape d'un objet diapositive pour ajouter des formes. Diverses propriétés de forme peuvent être configurées, telles que la couleur de remplissage, la couleur de contour, la position, l'angle, le type, etc.

:path=/static-assets/ppt/content-code-examples/get-started/get-started-2.cs
using IronPPT;
using IronPPT.Drawing; // Assuming this namespace contains `Shape` and `Color` classes
using IronPPT.Enums; // Assuming this namespace contains the `ShapeType` enum

// Load a PowerPoint presentation from the specified file
var document = new PresentationDocument("output.pptx");

// Create and configure a new shape, in this case, a triangle
Shape shape = new Shape
{
    Name = "triangle",             // Assign a name to the shape
    Type = ShapeType.Triangle,     // Set the shape type to Triangle
    Width = 100,                   // Set the width of the shape
    Height = 100,                  // Assumed height for the shape, should be set for visibility
    FillColor = new Color("#444444"), // Set the fill color of the shape
    OutlineColor = Color.Black,    // Set the outline color to black
    Position = new System.Drawing.Point(200, 200) // Set the position of the shape
};

// Ensure that the slides array has at least one slide to add the shape to
if (document.Slides.Count > 0)
{
    // Add the shape to the first slide
    document.Slides[0].AddShape(shape);
}
else
{
    // If there are no slides, handle the error or add a slide
    document.Slides.Add(new Slide()); // Assuming there's a way to add new slides
    document.Slides[0].AddShape(shape); // Add the shape to the newly added slide
}

// Export the PowerPoint presentation to a new file
document.Save("addShape.pptx");
Imports IronPPT
Imports IronPPT.Drawing ' Assuming this namespace contains `Shape` and `Color` classes
Imports IronPPT.Enums ' Assuming this namespace contains the `ShapeType` enum

' Load a PowerPoint presentation from the specified file
Private document = New PresentationDocument("output.pptx")

' Create and configure a new shape, in this case, a triangle
Private shape As New Shape With {
	.Name = "triangle",
	.Type = ShapeType.Triangle,
	.Width = 100,
	.Height = 100,
	.FillColor = New Color("#444444"),
	.OutlineColor = Color.Black,
	.Position = New System.Drawing.Point(200, 200)
}

' Ensure that the slides array has at least one slide to add the shape to
If document.Slides.Count > 0 Then
	' Add the shape to the first slide
	document.Slides(0).AddShape(shape)
Else
	' If there are no slides, handle the error or add a slide
	document.Slides.Add(New Slide()) ' Assuming there's a way to add new slides
	document.Slides(0).AddShape(shape) ' Add the shape to the newly added slide
End If

' Export the PowerPoint presentation to a new file
document.Save("addShape.pptx")
$vbLabelText   $csharpLabel

Ajouter une image

L'ajout d'une image à une diapositive est également une tâche simple. L'exemple de code ci-dessous ajoute une image à la première diapositive, modifie les propriétés de l'image telles que la position, l'angle, le nom, la largeur et la hauteur, puis enregistre la présentation mise à jour au format .pptx.

:path=/static-assets/ppt/content-code-examples/get-started/get-started-3.cs
using IronPPT;
using System.Drawing;

// This code demonstrates creating a new PowerPoint presentation, adding an image to it,
// modifying the image's properties, and exporting the presentation.

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

// Ensure there's at least one slide in the presentation
// Create the first slide if it doesn't exist yet
if (document.Slides.Count == 0)
{
    document.Slides.Add();
}

// Initialize an Image object
// Load an image from a file specified by the file path
// Ensure that "sample.png" exists at the specified path
Image image = new Image(); 
image.LoadFromFile("sample.png");

// Add the image to the first slide of the presentation
var newImage = document.Slides[0].AddImage(image);

// Edit the image's properties
// Set the position of the image using X and Y coordinates
newImage.Position = new Point(200, 200);

// Set the rotation angle of the image in degrees
newImage.Angle = 45;

// Set a name for the image, which can be useful for identification
newImage.Name = "new image";

// Set the dimensions of the image
newImage.Width = 150;
newImage.Height = 150;

// Export the PowerPoint presentation with the new image
document.Save("addImage.pptx");
Imports IronPPT
Imports System.Drawing

' This code demonstrates creating a new PowerPoint presentation, adding an image to it,
' modifying the image's properties, and exporting the presentation.

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

' Ensure there's at least one slide in the presentation
' Create the first slide if it doesn't exist yet
If document.Slides.Count = 0 Then
	document.Slides.Add()
End If

' Initialize an Image object
' Load an image from a file specified by the file path
' Ensure that "sample.png" exists at the specified path
Dim image As New Image()
image.LoadFromFile("sample.png")

' Add the image to the first slide of the presentation
Dim newImage = document.Slides(0).AddImage(image)

' Edit the image's properties
' Set the position of the image using X and Y coordinates
newImage.Position = New Point(200, 200)

' Set the rotation angle of the image in degrees
newImage.Angle = 45

' Set a name for the image, which can be useful for identification
newImage.Name = "new image"

' Set the dimensions of the image
newImage.Width = 150
newImage.Height = 150

' Export the PowerPoint presentation with the new image
document.Save("addImage.pptx")
$vbLabelText   $csharpLabel

Licences et assistance disponibles

IronPPT est une bibliothèque commerciale, mais des licences d'essai gratuites sont disponibles.

Pour plus de détails sur Iron Software, visitez notre site web à l'adresse suivante : https://ironsoftware.com/. Si vous avez besoin d'assistance ou si vous avez des questions, veuillez contacter notre équipe.

Support logiciel Iron Software

Pour une assistance générale et des questions techniques, n'hésitez pas à nous envoyer un courrier électronique à l'adresse suivante support@ironsoftware.com.

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