本篇文章将详细介绍如何使用Spire.Presentation来程序化地创建文本框并设置其形状格式, 包括线条,填充以及阴影等。
代码如下:
C#
//新建一个PowerPoint文档并获取第一个幻灯片
Presentation presentation = new Presentation();
ISlide slide = presentation.Slides[0];
//添加一个文本框(shape)到第一张幻灯片并添加文字。
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(80, 120, 600, 200));
string textString = "Spire.Presentation for .NET 是一款专业的 PowerPoint® 组件" +
"使用该组件,开发者可以在 .NET 平台上对 PowerPoint® 文档" +
"进行生成、读取、写入、修改、转换和打印等操作。" +
"作为一个独立的控件,Spire.Presentation for .NET " +
"的运行无需要安装 Microsoft PowerPoint。";
shape.AppendTextFrame(textString);
//设置shape线条颜色和宽度
shape.Line.FillType = FillFormatType.Solid;
shape.Line.Width = 3;
shape.Line.SolidFillColor.Color = Color.LightYellow;
//设置shape填充颜色为渐变色
shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient;
shape.Fill.Gradient.GradientShape = Spire.Presentation.Drawing.GradientShapeType.Linear;
shape.Fill.Gradient.GradientStops.Append(1f, KnownColors.SkyBlue);
shape.Fill.Gradient.GradientStops.Append(0, KnownColors.LightPink);
//设置shape阴影
Spire.Presentation.Drawing.OuterShadowEffect shadow = new Spire.Presentation.Drawing.OuterShadowEffect();
shadow.BlurRadius = 20;
shadow.Direction = 30;
shadow.Distance = 8;
shadow.ColorFormat.Color = Color.LightGray;
shape.EffectDag.OuterShadowEffect = shadow;
//设置shape向左旋转10度, 向右旋转为正
shape.Rotation = -10;
//保存并打开文档
presentation.SaveToFile("结果文档.pptx", FileFormat.Pptx2007);
System.Diagnostics.Process.Start("结果文档.pptx");
VB.NET
'新建一个PowerPoint文档并获取第一个幻灯片
Dim presentation As New Presentation()
Dim slide As ISlide = presentation.Slides(0)
'添加一个文本框(shape)到第一张幻灯片并添加文字。
Dim shape As IAutoShape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(80, 120, 600, 200))
Dim textString As String = "Spire.Presentation for .NET 是一款专业的 PowerPoint® 组件" + "使用该组件,开发者可以在 .NET 平台上对 PowerPoint® 文档" + "进行生成、读取、写入、修改、转换和打印等操作。" + "作为一个独立的控件,Spire.Presentation for .NET " + "的运行无需要安装 Microsoft PowerPoint。"
shape.AppendTextFrame(textString)
'设置shape线条颜色和宽度
shape.Line.FillType = FillFormatType.Solid
shape.Line.Width = 3
shape.Line.SolidFillColor.Color = Color.LightYellow
'设置shape填充颜色为渐变色
shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient
shape.Fill.Gradient.GradientShape = Spire.Presentation.Drawing.GradientShapeType.Linear
shape.Fill.Gradient.GradientStops.Append(1F, KnownColors.SkyBlue)
shape.Fill.Gradient.GradientStops.Append(0, KnownColors.LightPink)
'设置shape阴影
Dim shadow As New Spire.Presentation.Drawing.OuterShadowEffect()
shadow.BlurRadius = 20
shadow.Direction = 30
shadow.Distance = 8
shadow.ColorFormat.Color = Color.LightGray
shape.EffectDag.OuterShadowEffect = shadow
'设置shape向左旋转10度, 向右旋转为正
shape.Rotation = -10
'保存并打开文档
presentation.SaveToFile("结果文档.pptx", FileFormat.Pptx2007)
System.Diagnostics.Process.Start("结果文档.pptx")
效果图如下: