幻灯片元素教程

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#