这个快速示例需要如何使用 C# 在 PPTX 中删除文本。它包含有关所需资源的信息、逐步过程和使用 c#** **删除 PPTX 文本的工作示例代码。它共享过程细节,包括创建示例演示文稿、添加自选图形、通过添加文本创建文本框架以及删除文本。
使用 C# 在 PPTX 中删除文本的步骤
- 配置环境添加Aspose.Slides for .NET删除PPTX中的文字
- 使用 Presentation 类的实例创建一个默认的空演示文稿并访问第一张幻灯片
- 创建矩形类型的自动形状并在其中添加示例文本框
- 在文本框架内添加一部分文本,并使用 TextStrikethroughType 枚举器设置双线删除线
- 在文本框架内添加第二部分文本,并使用 TextStrikethroughType 枚举器设置单行删除线
- 在 PPTX 上保存带删除线的演示文稿
上述步骤描述了如何使用 C# 在演示文稿中删除文本。所有必需的类、方法和属性都按明确定义的顺序指定和使用以获得所需的输出,例如 Presentation 类用于创建空文件或加载现有 PPTX 文件,ShapeCollection 类用于在中添加自选图形在 PPTX 幻灯片中,TextStrikethroughType 枚举器用于为选定的文本部分设置所需的删除线类型。
使用 C# 在 PPTX 中删除文本的代码
using System; | |
using System.Drawing; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace TestSlides | |
{ | |
public class StrikeThroughText | |
{ | |
public static void StrikeText() | |
{ | |
String path = @"/Users/KnowledgeBase/TestData/"; | |
//Setting the API linence | |
License SlidesLicense = new License(); | |
SlidesLicense.SetLicense(path + "Conholdate.Total.Product.Family.lic"); | |
//Instantiate a Presentation class object to create a presentation | |
using (Presentation presentation = new Presentation()) | |
{ | |
//Insert a Blank empty slide inside the presentation | |
ISlide slide = presentation.Slides.AddEmptySlide(presentation.LayoutSlides.GetByType(SlideLayoutType.Blank)); | |
//Add a new autoshape of the Rectangle type | |
IAutoShape autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 0, 120, 300, 300); | |
// Filling the shape with no fill color | |
autoShape.FillFormat.FillType = FillType.NoFill; | |
//Add the text frame inside the autoshape | |
ITextFrame textFrame = autoShape.AddTextFrame("This is sample strikethrough text"); | |
// Set the textual properties on the portion | |
IPortionFormat portionFormat = textFrame.Paragraphs[0].Portions[0].PortionFormat; | |
portionFormat.FillFormat.FillType = FillType.Solid; | |
portionFormat.FillFormat.SolidFillColor.Color = Color.Red; | |
//Strikethrough with a double line | |
portionFormat.StrikethroughType = TextStrikethroughType.Double; | |
//Add a second line of text inside the shape | |
IPortion secondPortion = new Portion("Second text line "); | |
textFrame.Paragraphs[0].Portions.Add(secondPortion); | |
portionFormat = secondPortion.PortionFormat; | |
portionFormat.FillFormat.FillType = FillType.Solid; | |
portionFormat.FillFormat.SolidFillColor.Color = Color.Blue; | |
//Strikethrouh with a single line | |
portionFormat.StrikethroughType = TextStrikethroughType.Single; | |
// Save the presentation with strikethrough text on the disk | |
presentation.Save(path + "StrikethroughText.pptx", SaveFormat.Pptx); | |
} | |
} | |
} | |
} |
上面的例子演示了使用c#在PPT中的删除线文本。它使用 Presentation 类对象创建默认的空演示文稿,并使用 Presentation.Slides 属性访问幻灯片集合中的第一张默认幻灯片。创建一个 Rectangle 类型的自选图形,然后在其中添加文本。最后,通过使用 TextStrikethroughType 枚举器,设置所需的文本删除线并将带有删除线文本的演示文稿保存在磁盘上。
本教程指导我们使用 C# 删除演示文稿文本。如果您想了解在演示文稿中合并幻灯片的过程,请参阅 如何在C#中合并幻灯片 上的文章。