在文框本或形状上写入文字时,我们可以设置“溢出时缩排文字”,以避免文字过多而超出文本框。当然我们也可以设置“根据文字调整形状大小”,使形状大小自动适应文字。本文将为大家介绍如何使用Spire.Presentation实现这些操作。
C#
//创建Presentation对象
Presentation presentation = new Presentation();
//添加一个图形,设置AutoFitType为Normal, 表示文字自动适应图形
IAutoShape textShape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 150, 80));
textShape1.TextFrame.Text = "溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。";
textShape1.TextFrame.AutofitType = TextAutofitType.Normal;
//添加一个图形,设置AutoFitType为Shape, 表示图形自动适应文字
IAutoShape textShape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(350, 50, 150, 80));
textShape2.TextFrame.Text = "根据文字调整形状大小。";
textShape2.TextFrame.AutofitType = TextAutofitType.Shape;
//保存文档
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013);
VB.NET
'创建Presentation对象
Dim presentation As New Presentation()
'添加一个图形,设置AutoFitType为Normal, 表示文字自动适应图形
Dim textShape1 As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 50, 150, 80))
textShape1.TextFrame.Text = "溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。溢出时缩排文字。"
textShape1.TextFrame.AutofitType = TextAutofitType.Normal
'添加一个图形,设置AutoFitType为Shape, 表示图形自动适应文字
Dim textShape2 As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(350, 50, 150, 80))
textShape2.TextFrame.Text = "根据文字调整形状大小。"
textShape2.TextFrame.AutofitType = TextAutofitType.Shape
'保存文档
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013)