Rozpoczęcie pracy z IronPPT

Curtis Chau
Curtis Chau
Updated: 29 czerwca 2026

IronPowerPoint: Biblioteka PowerPoint dla .NET

IronPPT to biblioteka PowerPoint opracowana przez Iron Software. Doskonała w zapewnianiu solidnej funkcjonalności do pracy z prezentacjami PowerPoint w aplikacjach .NET.

  • Wczytywanie, manipulowanie i zapisywanie prezentacji PowerPoint. Łatwa praca z plikami .pptx i .ppt.
  • SlideSetup: Konfiguracja rozmiaru slajdu, orientacji, koloru tła i układu.
  • Tekst: Obsługa treści tekstu, stylów, dzielenie, dodawanie tekstu i dodawanie pól tekstowych.
  • Styl tekstu: Zarządzanie rodziną czcionek, rozmiarem, kolorem, pogrubieniem, kursywą, podkreśleniem i wyrównaniem.
  • Kształty: Dodawanie i manipulowanie kształtami, w tym ustawianie rozmiaru, pozycji, typu i obrotu.
  • Obrazy: Wstawianie obrazów do slajdów z opcjami skalowania, wyrównania i pozycjonowania.

Instalacja

Biblioteka IronPPT

Instalowanie IronPPT jest szybkie i proste. Dodaj pakiet przy użyciu następującej metody:

PM > Install-Package IronPPT

Alternatywnie, możesz pobrać go bezpośrednio z oficjalnej strony NuGet IronPPT.

Po instalacji, po prostu umiesc using IronPPT; na poczatku kodu C# aby rozpoczac.

Stosowanie klucza licencyjnego

Aby używać IronPPT, zastosuj ważny klucz licencyjny lub próbny, ustawiając właściwość LicenseKey. Dodaj następujący kod bezpośrednio po instrukcji importu i przed wywołaniem jakichkolwiek metod IronPPT:

/// <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.");
        }
    }
}

Przykłady kodu

Przeanalizujmy teraz kilka przykładów kodu i dostępnych funkcji.

Tworzenie pliku PowerPoint

Stworz prezentacje PowerPoint przez utworzenie instancji klasy PresentationDocument za pomoca jednego z jej konstruktorow. Uzyj metod AddSlide i AddText do dodawania odpowiednio slajdow i tekstu. Nastepnie uzyj metody Save aby wyeksportowac prezentacje PowerPoint.

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");

Dodawanie kształtu

Mozesz uzyc metody AddShape z obiektu slajdu do dodawania ksztaltow. Mozna skonfigurowac rozne wlasciwosci ksztaltu, takie jak kolor wypelnienia, kolor obrysu, polozenie, kat, typ i inne.

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");

Dodaj obraz

Dodanie obrazu do dowolnego slajdu to także proste zadanie. Poniższy przykład kodu dodaje obraz do pierwszego slajdu, modyfikuje właściwości obrazu, takie jak pozycja, kąt, nazwa, szerokość i wysokość, a następnie zapisuje zaktualizowaną prezentację jako plik .pptx.

using IronPPT;
using IronPPT.Models;

// 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.AddSlide(new Slide());
}

// 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 = (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");

Licencjonowanie i wsparcie dostępne

IronPPT to komercyjna biblioteka, ale dostępne są bezpłatne licencje próbne.

Więcej informacji o Iron Software można znaleźć na naszej stronie internetowej: https://ironsoftware.com/. Jeśli potrzebujesz wsparcia lub masz jakiekolwiek pytania, prosimy skontaktuj się z naszym zespołem.

Wsparcie Iron Software

W przypadku ogólnej pomocy i pytań technicznych, zapraszamy do kontaktu mailowego: support@ironsoftware.com.

Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podręczników.

Czytaj więcej

Gotowy, aby rozpocząć?

Nuget Downloads 6,931Wersja:2026.11właśnie wydany