AddTextFrame
AutoShape.AddTextFrame 方法
向形状添加一个新的 TextFrame。如果形状已经有 TextFrame,则仅更改其文本。
public ITextFrame AddTextFrame(string text)
参数 | 类型 | 描述 |
---|---|---|
text | String | 新 TextFrame 的默认文本。 |
示例
以下示例代码演示如何在 PowerPoint 演示文稿中添加水印文本。
[C#]
using (var presentation = new Presentation())
{
ISlide slide = presentation.Slides[0];
IAutoShape watermarkShape = slide.Shapes.AddAutoShape(ShapeType.Triangle, 0, 0, 150, 50);
ITextFrame watermarkTextFrame = watermarkShape.AddTextFrame("Watermark");
}
以下示例演示如何在幻灯片上创建文本框。
[C#]
// Instantiates Presentation
using (Presentation pres = new Presentation())
{
// Gets the first slide in the presentation
ISlide sld = pres.Slides[0];
// Adds an AutoShape with type set as Rectangle
IAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
// Adds TextFrame to the Rectangle
ashp.AddTextFrame(" ");
// Accesses the text frame
ITextFrame txtFrame = ashp.TextFrame;
// Creates the Paragraph object for text frame
IParagraph para = txtFrame.Paragraphs[0];
// Creates a Portion object for the paragraph
IPortion portion = para.Portions[0];
// Sets the text
portion.Text = "Aspose TextBox";
// Saves the presentation to disk
pres.Save("TextBox_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
以下示例演示如何在文本框中添加列。
[C#]
using (Presentation presentation = new Presentation())
{
// Gets the first slide in the presentation
ISlide slide = presentation.Slides[0];
// Add an AutoShape with type set as Rectangle
IAutoShape aShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);
// Add TextFrame to the Rectangle
aShape.AddTextFrame("所有这些列都限制在一个文本容器内 -- " +
"您可以添加或删除文本,而新的或剩余的文本会自动调整 " +
"以适应容器内。尽管如此,您不能让文本从一个容器流向另一个容器 -- " +
"我们告诉您 PowerPoint 的文本列选项是有限的!");
// Gets the text format of TextFrame
ITextFrameFormat format = aShape.TextFrame.TextFrameFormat;
// Specifies the number of columns in TextFrame
format.ColumnCount = 3;
// Specifies the spacing between columns
format.ColumnSpacing = 10;
// Saves the presentation
presentation.Save("ColumnCount.pptx", SaveFormat.Pptx);
}
另见
- interface ITextFrame
- class AutoShape
- namespace Aspose.Slides
- assembly Aspose.Slides