PPT处理控件Aspose.Slides功能演示:使用C#从PowerPoint文件中提取文本

  • 从PowerPoint幻灯片中提取文本
  • 从PowerPoint演示文稿中提取文本

为了处理PowerPoint演示文稿,Aspose提供Aspose.Slides for .NET旨在在.NET应用程序中实现PowerPoint自动化功能。它还提供了一些简单的方法来从PPTX演示文稿中提取文本。

>>你可以点击这里下载Aspose.Slides 最新版测试体验。

整合所有格式API处理控件Aspose.Total永久授权火热促销中,联系客服立马1分钟了解全部!


从C#中的PowerPoint幻灯片中提取文本

以下是从PowerPoint演示文稿中的幻灯片中提取文本的步骤。

  • 使用Presentation类加载演示文稿。
  • 使用SlideUtil.GetAllTextBoxes()方法将一张幻灯片中的所有文本框获取到ITextFrame数组中。
  • 遍历每个ITextFrame并使用ITextFrame.Paragraphs属性访问其文本。
  • 从段落的每个章节中检索并打印文本。

下面的代码示例演示如何使用C#从PowerPoint幻灯片中提取文本。

//Instatiate PresentationEx class that represents a PPTX filePresentation pptxPresentation = new Presentation("demo.pptx");//Get an Array of TextFrameEx objects from the first slideITextFrame[] textFramesSlideOne = SlideUtil.GetAllTextBoxes(pptxPresentation.Slides[0]);//Loop through the Array of TextFramesfor (int i = 0; i < textFramesSlideOne.Length; i++)    //Loop through paragraphs in current TextFrame    foreach (Paragraph para in textFramesSlideOne[i].Paragraphs)        //Loop through portions in the current Paragraph        foreach (Portion port in para.Portions)        {            //Display text in the current portion            Console.WriteLine(port.Text);            //Display font height of the text            Console.WriteLine(port.PortionFormat.FontHeight);            //Display font name of the text            Console.WriteLine(port.PortionFormat.LatinFont.FontName);        }  }}

从C#中的PowerPoint演示文稿中提取文本

还可以使用Aspose.Slides for .NET从整个PowerPoint演示文稿中提取文本。以下是执行此操作的步骤。

  • 使用Presentation类加载演示文稿。
  • 使用SlideUtil.GetAllTextFrames()方法获取演示文稿中的所有文本框架。
  • 遍历每个ITextFrame并访问其Paragraphs。
  • 访问段落的各个部分并打印其文本。

下面的代码示例演示如何从PowerPoint演示文稿中提取文本。

//Instatiate Presentation class that represents a PPTX filePresentation pptxPresentation = new Presentation("demo.pptx");//Get an Array of ITextFrame objects from all slides in the PPTXITextFrame[] textFramesPPTX = Aspose.Slides.Util.SlideUtil.GetAllTextFrames(pptxPresentation, true);//Loop through the Array of TextFramesfor (int i = 0; i < textFramesPPTX.Length; i++)//Loop through paragraphs in current ITextFrameforeach (IParagraph para in textFramesPPTX[i].Paragraphs)//Loop through portions in the current IParagraphforeach (IPortion port in para.Portions){//Display text in the current portionConsole.WriteLine(port.Text);//Display font height of the textConsole.WriteLine(port.PortionFormat.FontHeight);//Display font name of the textif (port.PortionFormat.LatinFont != null)Console.WriteLine(port.PortionFormat.LatinFont.FontName);}}}

如果你想试用Aspose的全部完整功能,可 联系在线客服获取30天临时授权体验。


还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月5日
下一篇 2021年1月5日

相关推荐

发表回复

登录后才能评论