開始使用IronPPT

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

IronPowerPoint:.NET 的 PowerPoint 庫

IronPPT 是由 Iron Software 開發的一個 PowerPoint 函式庫。 它在為.NET應用程式處理PowerPoint簡報時提供強大的功能。

  • 加載、操作和保存 PowerPoint 簡報。 輕鬆處理 .pptx 和 .ppt 文件。
  • 幻燈片設定:配置幻燈片大小、方向、背景顏色和佈局。
  • 處理文本內容、樣式、拆分、附加文本和添加文本框。
  • 文字樣式:管理字體系列、大小、顏色、粗體、斜體、底線和對齊方式。
  • 形狀:添加和操作形狀,包括設置大小、位置、類型和旋轉。
  • 圖片:將圖片插入到幻燈片中,並提供縮放、對齊和定位的選項。

安裝

IronPPT 庫

安裝 IronPPT 是快速且簡單的。 使用以下方法添加套件:

Install-Package IronPPT

或者,您可以直接從官方下載IronPPT NuGet 網站.

安裝後,只需在 C# 代碼的頂部包含 using IronPPT; 即可開始。

套用授權金鑰

要使用IronPPT,請通過設置 LicenseKey 屬性來應用有效的許可證或試用密鑰。 在 import 語句之後以及呼叫任何 IronPPT 方法之前,立即添加以下程式碼:

:path=/static-assets/ppt/content-code-examples/get-started/get-started-license.cs
IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01";
IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01"
VB   C#

程式碼範例

讓我們探索一些程式碼範例和可用的功能。

建立 PowerPoint 檔案

通過使用其構造函數之一實例化 PresentationDocument 類來創建 PowerPoint 演示文稿。 使用 AddSlide 和 AddText 方法分別添加幻燈片和文本。 之後,使用 Save 方法匯出 PowerPoint 簡報。

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

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

// Add empty slide
document.AddSlide();

// Add slide object
Slide slide = new Slide();
slide.AddText("Hello!");
document.AddSlide(slide);

// Export PowerPoint presentation
document.Save("output.pptx");
Imports IronPPT

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

' Add empty slide
document.AddSlide()

' Add slide object
Dim slide As New Slide()
slide.AddText("Hello!")
document.AddSlide(slide)

' Export PowerPoint presentation
document.Save("output.pptx")
VB   C#

新增形狀

您可以使用幻灯片对象中的 AddShape 方法來添加形狀。可以配置各種形狀屬性,如填充顏色、輪廓顏色、位置、角度、類型等。

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

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

// Configure new shape
Shape shape = new Shape();
shape.Name = "triangle";
shape.Type = IronPPT.Enums.ShapeType.Triangle;
shape.Width = 100;
shape.FillColor = new Color("#444444");
shape.OutlineColor = Color.Black;
shape.Position = (200, 200);

// Add shape
document.Slides[0].AddShape(shape);

// Export PowerPoint presentation
document.Save("addShape.pptx");
Imports IronPPT

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

' Configure new shape
Private shape As New Shape()
shape.Name = "triangle"
shape.Type = IronPPT.Enums.ShapeType.Triangle
shape.Width = 100
shape.FillColor = New Color("#444444")
shape.OutlineColor = Color.Black
shape.Position = (200, 200)

' Add shape
document.Slides(0).AddShape(shape)

' Export PowerPoint presentation
document.Save("addShape.pptx")
VB   C#

添加圖片

將圖像添加到任何幻燈片也是一項簡單的任務。 下面的程式碼範例將圖片添加到第一張幻燈片,修改圖片的屬性如位置、角度、名稱、寬度和高度,然後將更新後的簡報儲存為.pptx文件。

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

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

// Add image
Image image = new Image();
image.LoadFromFile("sample.png");
var newImage = document.Slides[0].AddImage(image);

// Edit image's properties
newImage.Position = (200, 200);
newImage.Angle = 45;
newImage.Name = "new image";
newImage.Width = 150;
newImage.Height = 150;

// Export PowerPoint presentation
document.Save("addImage.pptx");
Imports IronPPT

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

' Add image
Private image As New Image()
image.LoadFromFile("sample.png")
Dim newImage = document.Slides(0).AddImage(image)

' Edit image's properties
newImage.Position = (200, 200)
newImage.Angle = 45
newImage.Name = "new image"
newImage.Width = 150
newImage.Height = 150

' Export PowerPoint presentation
document.Save("addImage.pptx")
VB   C#

授權與支持可用

IronPPT 是一個商業程式庫,但提供免費試用許可證這裡.

欲了解有關 Iron Software 的更多詳細資訊,請造訪我們的網站:https://ironsoftware.com/。 如果您需要支援或有任何疑問,請聯絡我們的團隊.

Iron Software 支援

如需一般協助和技術問題,歡迎發送電子郵件至:support@ironsoftware.com