IRONSOFTWAREHOME

IronPPT入门指南

Curtis Chau
Curtis Chau
Updated: 2026年6月29日

IronPowerPoint:适用于 .NET 的 PowerPoint 库

IronPPT是由Iron Software开发的PowerPoint库。 它在为 .NET 应用程序中处理 PowerPoint 演示文稿提供强大的功能方面表现出色。

  • 加载、编辑和保存 PowerPoint 演示文稿。 轻松处理 .pptx 和 .ppt 文件。
  • 幻灯片设置:配置幻灯片大小、方向、背景颜色和布局。
  • 文本:处理文本内容、样式、拆分、追加文本和添加文本框。
  • 文本样式:管理字体系列、大小、颜色、粗体、斜体、下划线和对齐方式。
  • 形状:添加和操作形状,包括设置大小、位置、类型和旋转。
  • 图片:在幻灯片中插入图片,并可设置缩放、对齐和定位等选项。

安装

IronPPT库

安装 IronPPT 既快捷又简单。 使用以下方法添加软件包:

PM > Install-Package IronPPT

或者,您可以直接从IronPPT NuGet 官方网站下载。

安装后,只需在C#代码顶部包含using IronPPT;即可开始。

应用许可证密钥

要使用 IronPPT,请通过设置LicenseKey属性来应用有效的许可证或试用密钥。 在导入语句之后、调用任何 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.");
        }
    }
}

代码示例

让我们来看一些代码示例和可用功能。

创建 PowerPoint 文件

通过使用其构造函数之一实例化PresentationDocument类来创建PowerPoint演示文稿。 使用AddText方法分别添加幻灯片和文本。 然后,使用Save方法导出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");

添加形状

您可以从幻灯片对象中使用AddShape方法添加形状。可以配置各种形状属性,如填充颜色、轮廓颜色、位置、角度、类型等。

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

添加图片

向任何幻灯片添加图片也是一件很简单的事情。 下面的代码示例向第一张幻灯片添加图像,修改图像的属性,例如位置、角度、名称、宽度和高度,然后将更新后的演示文稿保存为 .pptx 文件。

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

可用的许可和支持

IronPPT是一个商业库,但提供免费试用许可证

有关 Iron Software 的更多详细信息,请访问我们的网站:https://ironsoftware.com/ 。 如果您需要帮助或有任何疑问,请联系我们的团队

Iron 软件支持

如需一般帮助或有任何技术问题,请随时发送电子邮件至:support@ironsoftware.com

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

...
阅读更多

准备开始了吗?

Nuget Downloads 6,070版本:2026.9刚刚发布

C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package IronPPT
nuget.org/packages/IronPPT/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索"IronPPT"
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

  1. 下载并解压IronPPT到你的解决方案目录中的~/Libs等位置
  2. 在Visual Studio解决方案资源管理器中,右键单击引用。选择浏览,"IronPPT.dll"

许可证从$999

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户