幻灯片元素教程
IronPPT 是一个强大的 PowerPoint 库,旨在帮助 .NET C# 开发人员将创建、读取和编辑 PowerPoint 演示文稿的功能无缝集成到其应用程序中。 在 PowerPoint 演示文稿的上下文中,幻灯片是构建和组织内容的基础元素。
目录
- 添加文本
- 文本内容 (添加、附加和移除)
- 设置样式 (字体系列和大小,颜色,加粗和斜体,删除线,下划线)
- 添加图片
- 加载图像 (文件和文件流)
- 设置尺寸和角度 (宽度和高度)
- Set location
- 添加形状
- SetShapeType
- 设置尺寸 (宽度和高度)
- Set the fill and outline color
- Set location
开始使用IronPPT
立即在您的项目中开始使用IronPPT,并享受免费试用。
添加文字
文本内容
无论您是创建新的演示文稿还是编辑现有的,文本管理工具都为您提供文本位置和格式化的完全控制,使您能够设计出清晰且专业传达信息的幻灯片。
: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")
设置样式
通过设置字体大小、颜色、样式、删除线和下划线等属性,可以自定义文本的视觉外观。应用这些样式可以增强文本的呈现效果,并改善文档的整体外观。
: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")
添加图片
调整图像设置以实现最佳显示。 正确的配置可以确保图像视觉上令人愉悦,并与其上下文适当匹配。
: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")
添加形状
通过定义形状的类型和尺寸,可以轻松地在演示文稿中添加和自定义形状(宽度和高度)、填充色和轮廓色,以及在幻灯片上的位置。
: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")