已更新 2025年1月9日
分享:

幻燈片元素教程

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

IronPPT 是一個強大的 PowerPoint 函式庫,旨在幫助 .NET C# 開發人員將創建、读取和编辑 PowerPoint 演示文稿的功能无缝集成到其应用程序中。 在 PowerPoint 簡報中,幻燈片是構建和組織內容的基礎元素。

目錄


新增文字

文字內容

無論您是創建新簡報還是編輯現有的簡報,文本管理工具都能讓您完全控制文本的放置和格式,幫助您設計出清晰且專業地傳達訊息的幻燈片。

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-text.cs
using IronPPT;
using IronPPT.Models;

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

// Add text
var text = document.Slides[0].AddText("Hello");

// Append text
text.Append(new Text(" There!"));

// Remove text
document.Slides[0].Texts[0].Remove();

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

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

' Add text
Private text = document.Slides(0).AddText("Hello")

' Append text
text.Append(New Text(" There!"))

' Remove text
document.Slides(0).Texts(0).Remove()

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

設置樣式

樣式化文本允許您通過定義屬性如字型大小、顏色、樣式、刪除線和底線來自訂其視覺外觀。應用這些樣式可以增強文本的呈現效果並改善文檔的整體外觀。

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-text-style.cs
using IronPPT;
using IronPPT.Models;
 
var document = new PresentationDocument();

// Customize text style
var textStyle = new TextStyle
{
    IsBold = true,
    IsItalic = true,
    Color = Color.Blue,
    Strike = StrikValue.SingleStrike,
    Outline = true,
    NoProof = true,
    Spacing = 10.0,
    Underline = new Underline { LineValue = UnderlineValues.Single, Color = Color.Red },
    Languages = "en-US",
    SpecVanish = false,
};

// Add style to text
var text = new Text("Hello World");
text.TextStyle = textStyle;

// Add text
document.Slides[0].AddText(text);

document.Save("textStyle.pptx");
Imports IronPPT
Imports IronPPT.Models

Private document = New PresentationDocument()

' Customize text style
Private textStyle = New TextStyle With {
	.IsBold = True,
	.IsItalic = True,
	.Color = Color.Blue,
	.Strike = StrikValue.SingleStrike,
	.Outline = True,
	.NoProof = True,
	.Spacing = 10.0,
	.Underline = New Underline With {
		.LineValue = UnderlineValues.Single,
		.Color = Color.Red
	},
	.Languages = "en-US",
	.SpecVanish = False
}

' Add style to text
Private text = New Text("Hello World")
text.TextStyle = textStyle

' Add text
document.Slides(0).AddText(text)

document.Save("textStyle.pptx")
VB   C#

添加圖片

調整圖像設定以達到最佳顯示效果。 適當的配置可確保影像視覺上吸引人,並適合其上下文。

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-image.cs
using IronPPT;
using IronPPT.Models;
 
// Create new PowerPoint presentation
var document = new PresentationDocument();
 
// Add image
Image image = new Image();
image.LoadFromFile("sample.png");
var newImage = document.AddImage(image, 0);
 
// 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
Imports IronPPT.Models

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

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

' 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#

添加形狀

輕鬆地在您的演示文稿中添加和自訂形狀,通過定義它們的類型和尺寸(寬度和高度)、填充和輪廓顏色,以及在幻燈片上的位置。

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-image.cs
using IronPPT;
using IronPPT.Models;
 
// Create new PowerPoint presentation
var document = new PresentationDocument();
 
// Add image
Image image = new Image();
image.LoadFromFile("sample.png");
var newImage = document.AddImage(image, 0);
 
// 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
Imports IronPPT.Models

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

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

' 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#
查克尼思·賓

查克尼思·賓

軟體工程師

Chaknith 致力於 IronXL 和 IronBarcode。他在 C# 和 .NET 方面擁有豐富的專業知識,協助改進軟體並支持客戶。他從用戶互動中獲得的洞察力有助於提高產品、文檔和整體體驗。