Placeholder
Shape.Placeholder 属性
返回形状的占位符。如果形状没有占位符,则返回null。只读 IPlaceholder
。
public IPlaceholder Placeholder { get; }
示例
以下示例演示如何更改占位符中的文本。
[C#]
// 实例化一个 Presentation 类
using (Presentation pres = new Presentation("ReplacingText.pptx"))
{
// 访问第一张幻灯片
ISlide sld = pres.Slides[0];
// 迭代形状以查找占位符
foreach (IShape shp in sld.Shapes)
if (shp.Placeholder != null)
{
// 更改每个占位符中的文本
((IAutoShape)shp).TextFrame.Text = "这是一个占位符";
}
// 保存演示文稿到磁盘
pres.Save("output_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
以下示例演示如何在占位符中设置提示文本。
[C#]
using (Presentation pres = new Presentation("Presentation2.pptx"))
{
ISlide slide = pres.Slides[0];
foreach (IShape shape in slide.Slide.Shapes) // 迭代幻灯片
{
if (shape.Placeholder != null && shape is AutoShape)
{
string text = "";
if (shape.Placeholder.Type == PlaceholderType.CenteredTitle) // PowerPoint 显示 "点击添加标题"
{
text = "添加标题";
}
else if (shape.Placeholder.Type == PlaceholderType.Subtitle) // 添加副标题
{
text = "添加副标题";
}
((IAutoShape)shape).TextFrame.Text = text;
Console.WriteLine($"占位符文本: {text}");
}
}
pres.Save("Placeholders_PromptText.pptx", SaveFormat.Pptx);
}
另请参见
- 接口 IPlaceholder
- 类 Shape
- 命名空间 Aspose.Slides
- 程序集 Aspose.Slides