翻譯|使用教程|編輯:李顯亮|2021-03-08 10:20:37.323|閱讀 295 次
概述:我們可能經常需要從PowerPoint幻燈片中提取文本以執行文本分析。另一方面,可能需要提取文本并將其保存在文件或數據庫中以進行進一步處理。因此,本文介紹了如何使用C#從PowerPoint演示文稿中提取文本。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
有時需要從PowerPoint幻燈片中提取文本以執行文本分析。另一方面,可能需要提取文本并將其保存在文件或數據庫中以進行進一步處理。因此,本文介紹了如何使用C#從PowerPoint演示文稿中提取文本。特別是,將學習如何從特定的幻燈片或整個演示文稿中提取文本。
為了處理PowerPoint演示文稿,Aspose提供Aspose.Slides for .NET旨在在.NET應用程序中實現PowerPoint自動化功能。它還提供了一些簡單的方法來從PPTX演示文稿中提取文本。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
以下是從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從整個PowerPoint演示文稿中提取文本。以下是執行此操作的步驟。
下面的代碼示例演示如何從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的全部完整功能,可 聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn