没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|行业资讯|编辑:郝浩|2013-08-07 12:55:32.000|阅读 2522 次
概述:如何从演示文稿中提取文本?本文以Microsoft PowerPoint PPTX演示文稿为例,为你介绍如何用Aspose.Slides控件从中提取文本。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
开发人员需要从演示文稿中提取文本,这并不罕见。要做到这一点,你需要从演示文稿所有不同图形的幻灯片中提取文本。为此,本文以Microsoft PowerPoint PPTX演示文稿为例, 为你介绍如何用Aspose.Slides控件从中提取文本。无论是从一张幻灯片中提取文本,还是从演示文稿的所有幻灯片中提取文本,Aspose.Slides使用静态方法PresentationScanner都能帮你做到。提取的文本会自动打包在命名空间Aspose.Slides.Util下面。
Aspose.Slides for .NET提供一个叫做Aspose.Slides.Util的命名空间,它包括一个PresentationScanner类。这个类显示了多个从一页演示文稿或幻灯片中提取文本的重载静态方法。 从PPTX演示幻灯片中提取文本,可以使用PresentationScanner类下面显示的重载静态方法GetAllTextBoxes。这个方法接收SlideEx对象作为一个参数。
执行时,SlideEx方法扫描经过的幻灯片上的所有文本,作为参数返回一组TextFrameEx对象。这意味着与文本相关的任何文本格式都适用。下面的一段代码显示在第一张幻灯片上提取文本:
//Instatiate PresentationEx class that represents a PPTX file
using(PresentationEx pptxPresentation = new PresentationEx("d:\\pptx\\testx.pptx"))
{
//Get an Array of TextFrameEx objects from the first slide
TextFrameEx[] textFramesSlideOne = SlideUtil.GetAllTextBoxes(pptxPresentation.Slides[0]);
//Loop through the Array of TextFrames
for(int i=0;i<textFramesSlideOne.Length;i++)
//Loop through paragraphs in current TextFrame
foreach( ParagraphEx para in textFramesSlideOne[i].Paragraphs )
//Loop through portions in the current Paragraph
foreach (PortionEx port in para.Portions)
{
//Display text in the current portion
Console.WriteLine(port.Text);
//Display font height of the text
Console.WriteLine(port.FontHeight);
//Display font name of the text
Console.WriteLine(port.LatinFont.FontName);
}
}
'Instatiate PresentationEx class that represents a PPTX file
Using Dim pptxPresentation As New PresentationEx("d:\pptx\testx.pptx")
'Get an Array of TextFrameEx objects from the first slide
Dim textFramesSlideOne() As TextFrameEx = SlideUtil.GetAllTextBoxes(pptxPresentation.Slides(0))
'Loop through the Array of TextFrames
For i As Integer = 0 To textFramesSlideOne.Length - 1
'Loop through paragraphs in current TextFrame
For Each para As ParagraphEx In textFramesSlideOne(i).Paragraphs
'Loop through portions in the current Paragraph
For Each port As PortionEx In para.Portions
'Display text in the current portion
Console.WriteLine(port.Text)
'Display font height of the text
Console.WriteLine(port.FontHeight)
'Display font name of the text
Console.WriteLine(port.LatinFont.FontName)
Next port
Next para
Next i
End Using
要扫描整个演示文稿的文本,可以使用 PresentationScanner类显示的静态方法GetAllTextFrames。它包含两个参数:
1. 一个PresentationEx对象:显示当前正从中提取文本的PPTX演示文稿
2. 一个布尔值:决定当文本正从演示文稿中扫描时,主幻灯片是否包含在内。
这种方法将返回一组TextFrameEx对象,带有完整的文本格式信息。下面的代码表示扫描来自于演示文稿的文本和格式信息,包括主幻灯片。
//Instatiate PresentationEx class that represents a PPTX file
using(PresentationEx pptxPresentation = new PresentationEx("d:\\pptx\\testx.pptx"))
{
//Get an Array of TextFrameEx objects from all slides in the PPTX
TextFrameEx[] textFramesPPTX = SlideUtil.GetAllTextFrames(pptxPresentation, true);
//Loop through the Array of TextFrames
for (int i = 0; i < textFramesPPTX.Length; i++)
//Loop through paragraphs in current TextFrame
foreach (ParagraphEx para in textFramesPPTX[i].Paragraphs)
//Loop through portions in the current Paragraph
foreach (PortionEx port in para.Portions)
{
//Display text in the current portion
Console.WriteLine(port.Text);
//Display font height of the text
Console.WriteLine(port.FontHeight);
//Display font name of the text
Console.WriteLine(port.LatinFont.FontName);
}
}
'Instatiate PresentationEx class that represents a PPTX file
Using Dim pptxPresentation As New PresentationEx("d:\pptx\testx.pptx")
'Get an Array of TextFrameEx objects from all slides in the PPTX
Dim textFramesPPTX() As TextFrameEx = SlideUtil.GetAllTextBoxes(pptxPresentation.Slides(0))
'Loop through the Array of TextFrames
For i As Integer = 0 To textFramesPPTX.Length - 1
'Loop through paragraphs in current TextFrame
For Each para As ParagraphEx In textFramesPPTX(i).Paragraphs
'Loop through portions in the current Paragraph
For Each port As PortionEx In para.Portions
'Display text in the current portion
Console.WriteLine(port.Text)
'Display font height of the text
Console.WriteLine(port.FontHeight)
'Display font name of the text
Console.WriteLine(port.LatinFont.FontName)
Next port
Next para
Next i
End Using
Aspose.Slides.Util.SlideUtil类显示多个可供选择的动态方法来扫描演示文稿或幻灯片中的文本。格式信息也连同扫描的文件被提取出来。 如果你也遇到需要从演示文稿中提取文本或类似的难题,不妨试试Aspose.Slides,相信它会带给你不一样的体验和收获。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
文章转载自:慧都控件网Iron Software 为.NET开发者提供了难得的“即插即用”组件体验,无论是做内部工具,还是开发商业软件,都能大幅提升你的开发效率与产品质量。这款宝藏控件,不妨你也来试试!
TestComplete通过与Git、Jenkins和Zephyr的深度集成,构建了一个完整的持续测试生态系统:从代码变更的智能感知到批量测试的自动化执行,再到测试管理的智能化分析,实现了测试流程的全链路自动化。这种端到端的集成方案不仅显著提升了测试效率和质量,更通过实时反馈和可视化管理,为团队提供了精准的代码质量洞察。
微服务架构带来了灵活性,但也让测试变得复杂:不同协议适配费时费力、服务频繁变更导致测试用例维护困难、依赖环境搭建和稳定更是令人头疼。这些挑战常常成为敏捷交付和质量保障的瓶颈。Parasoft SOAtest正是为应对这些复杂分布式系统测试难题而设计的平台。它通过三大核心能力,帮助团队更从容地驾驭微服务测试:
HOOPS SDK为增材制造软件开发提供了从CAD数据读取、模型处理、可视化到文档生成的完整技术栈。无论是桌面端的工业级打印控制系统,还是基于云的在线制造平台,开发者都可通过HOOPS快速构建稳定可靠、用户体验优良的3D打印软件。
Aspose.Slides是第一个能在用户的应用程序中对PowerPoint文档进行管理的组件。
Aspose.Slides for Reporting ServicesAspose.Slides for Reporting Services 是惟一的能在Microsoft SQL Server 2005和2008 Reporting Services 中以 Microsoft PowerPoint PPT 和 PPS 格式生成报表的解决方案。
Aspose.Slides for JasperReportsAspose.Slides for JasperReports 是专门为JasperReports用户开发的一种标准组件,以帮助他们将其Java应用程序中的报表能够简单地导出为Microsoft PowerPoint Presentation (PPT)和Microsoft PowerPoint Show (PPS)格式。
Aspose.Slides for SharePointAspose.Slides for SharePoint使您在一个SharePoint应用程序中读取和转换PowerPoint文件而不需要使用Microsoft PowerPoint。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号