翻譯|使用教程|編輯:李顯亮|2021-03-08 10:20:37.323|閱讀 295 次
概述:我們可能經(jīng)常需要從PowerPoint幻燈片中提取文本以執(zhí)行文本分析。另一方面,可能需要提取文本并將其保存在文件或數(shù)據(jù)庫(kù)中以進(jìn)行進(jìn)一步處理。因此,本文介紹了如何使用C#從PowerPoint演示文稿中提取文本。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
有時(shí)需要從PowerPoint幻燈片中提取文本以執(zhí)行文本分析。另一方面,可能需要提取文本并將其保存在文件或數(shù)據(jù)庫(kù)中以進(jìn)行進(jìn)一步處理。因此,本文介紹了如何使用C#從PowerPoint演示文稿中提取文本。特別是,將學(xué)習(xí)如何從特定的幻燈片或整個(gè)演示文稿中提取文本。
為了處理PowerPoint演示文稿,Aspose提供Aspose.Slides for .NET旨在在.NET應(yīng)用程序中實(shí)現(xiàn)PowerPoint自動(dòng)化功能。它還提供了一些簡(jiǎn)單的方法來(lái)從PPTX演示文稿中提取文本。
>>你可以點(diǎn)擊這里下載Aspose.Slides 最新版測(cè)試體驗(yàn)。
以下是從PowerPoint演示文稿中的幻燈片中提取文本的步驟。
下面的代碼示例演示如何使用C#從PowerPoint幻燈片中提取文本。
//Instatiate PresentationEx class that represents a PPTX file Presentation pptxPresentation = new Presentation("demo.pptx"); //Get an Array of TextFrameEx objects from the first slide ITextFrame[] 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 (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); } } }
還可以使用Aspose.Slides for .NET從整個(gè)PowerPoint演示文稿中提取文本。以下是執(zhí)行此操作的步驟。
下面的代碼示例演示如何從PowerPoint演示文稿中提取文本。
//Instatiate Presentation class that represents a PPTX file Presentation pptxPresentation = new Presentation("demo.pptx"); //Get an Array of ITextFrame objects from all slides in the PPTX ITextFrame[] textFramesPPTX = Aspose.Slides.Util.SlideUtil.GetAllTextFrames(pptxPresentation, true); //Loop through the Array of TextFrames for (int i = 0; i < textFramesPPTX.Length; i++) //Loop through paragraphs in current ITextFrame foreach (IParagraph para in textFramesPPTX[i].Paragraphs) //Loop through portions in the current IParagraph foreach (IPortion 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 if (port.PortionFormat.LatinFont != null) Console.WriteLine(port.PortionFormat.LatinFont.FontName); } } }
如果你想試用Aspose的全部完整功能,可 聯(lián)系在線客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn