Erste Schritte mit IronPPT
IronPowerPoint: PowerPoint-Bibliothek for .NET
IronPPT ist eine von Iron Software entwickelte PowerPoint-Bibliothek. Es zeichnet sich durch robuste Funktionalität für die Arbeit mit PowerPoint-Präsentationen in .NET-Anwendungen aus.
- Laden, Bearbeiten und Speichern von PowerPoint-Präsentationen. Einfach mit .pptx- und .ppt-Dateien arbeiten.
- SlideSetup: Konfigurieren von Foliengröße, Ausrichtung, Hintergrundfarbe und Layout.
- Text: Umgang mit Textinhalten, Stilen, Teilen, Anhängen von Text und Hinzufügen von Textfeldern.
- TextStyle: Verwaltung von Schriftfamilie, Größe, Farbe, Fett, Kursiv, Unterstreichen und Ausrichtung.
- Shapes: Hinzufügen und Bearbeiten von Formen, einschließlich Größen-, Positions-, Typ- und Rotationsfestlegung.
- Bilder: Einfügen von Bildern in Folien mit Optionen zur Skalierung, Ausrichtung und Positionierung.
PowerPoint-Präsentation C#-Bibliothek for .NET
- Laden Sie die C#-Bibliothek zur Bearbeitung von PowerPoint-Präsentationen herunter.
- Erstellen und Bearbeiten von .pptx- oder .ppt-Dokumenten
- Verwalten Sie Folieneigenschaften wie Reihenfolge, Sichtbarkeit und Inhaltsrotation.
- Fügen Sie Folienelemente wie Text, Bilder und Formen hinzu.
- Gestalten Sie Ihre Inhalte ganz einfach
Installation
IronPPT-Bibliothek
Die Installation von IronPPT ist schnell und einfach. Fügen Sie das Paket mit der folgenden Methode hinzu:
Install-Package IronPPT
Alternativ können Sie es direkt von der offiziellen IronPPT NuGet-Website herunterladen.
Nach der Installation fügen Sie einfach using IronPPT; am Anfang Ihres C#-Codes ein, um loszulegen.
Lizenzschlüssel anwenden
Um IronPPT zu verwenden, wenden Sie einen gültigen Lizenz- oder Testschlüssel an, indem Sie die LicenseKey-Eigenschaft setzen. Fügen Sie den folgenden Code unmittelbar nach der Importanweisung und vor dem Aufrufen von IronPPT-Methoden hinzu:
: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
Beispiele für Code
Lassen Sie uns einige Codebeispiele und die verfügbaren Funktionen erkunden.
PowerPoint-Datei erstellen
Erstellen Sie die PowerPoint-Präsentation, indem Sie die Klasse PresentationDocument mithilfe eines ihrer Konstruktoren instanziieren. Verwenden Sie die Methoden AddSlide und AddText, um Folien bzw. Text hinzuzufügen. Anschließend verwenden Sie die Methode Save, um die PowerPoint-Präsentation zu exportieren.
: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")
Form hinzufügen
Sie können die Methode AddShape eines Folienobjekts verwenden, um Formen hinzuzufügen. Verschiedene Formeigenschaften lassen sich konfigurieren, z. B. Füllfarbe, Umrissfarbe, Position, Winkel, Typ und mehr.
: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")
Bild hinzufügen
Ein Bild zu einer Folie hinzuzufügen, ist einfach. Das folgende Codebeispiel fügt der ersten Folie ein Bild hinzu, ändert die Bildeigenschaften wie Position, Winkel, Name, Breite und Höhe und speichert dann die aktualisierte Präsentation als .pptx-Datei.
: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")
Lizenzierung & Support verfügbar
IronPPT ist eine kommerzielle Bibliothek, aber kostenlose Testlizenzen sind verfügbar.
Für weitere Details zu Iron Software besuchen Sie unsere Website unter: https://ironsoftware.com/. Wenn Sie Unterstützung benötigen oder Anfragen haben, kontaktieren Sie unser Team.
Iron Software Support
Für allgemeine Unterstützung und technische Fragen senden Sie uns gerne eine E-Mail an: support@ironsoftware.com.

