翻譯|使用教程|編輯:李顯亮|2021-08-03 10:04:42.233|閱讀 378 次
概述:有時(shí)需要從 PowerPoint 幻燈片中提取文本以執(zhí)行文本分析。另一方面,可能希望提取文本并將其保存在文件或數(shù)據(jù)庫(kù)中以供進(jìn)一步處理。據(jù)此,本文介紹了如何使用 Java 從 PowerPoint 演示文稿中提取文本。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
有時(shí)需要從 PowerPoint 幻燈片中提取文本以執(zhí)行文本分析。另一方面,可能希望提取文本并將其保存在文件或數(shù)據(jù)庫(kù)中以供進(jìn)一步處理。據(jù)此,本文介紹了如何使用 Java 從 PowerPoint 演示文稿中提取文本。特別是,您將學(xué)習(xí)如何從特定幻燈片或整個(gè)演示文稿中提取文本。
為了操作 PowerPoint 演示文稿,我們將使用Aspose.Slides for Java,旨在在 Java 應(yīng)用程序中實(shí)現(xiàn) PowerPoint 自動(dòng)化功能。它還提供了一些從 PPT/PPTX 演示文稿中提取文本的簡(jiǎn)單方法。
>>你可以點(diǎn)擊這里下載Aspose.Slides 最新版測(cè)試體驗(yàn)。
以下是使用 Java 從 PowerPoint 演示文稿中的幻燈片中提取文本的步驟。
以下代碼示例展示了如何從 PowerPoint 幻燈片中提取文本。
//Instatiate PresentationEx class that represents a PPTX file Presentation pptxPresentation = new Presentation("presentation.pptx"); //Get an Array of ITextFrame objects from the first slide ITextFrame[] textFramesSlideOne = SlideUtil.getAllTextBoxes(pptxPresentation.getSlides().get_Item(1)); //Loop through the Array of TextFrames for (int i = 0; i < textFramesSlideOne.length; i++) { //Loop through paragraphs in current TextFrame for (IParagraph para : textFramesSlideOne[i].getParagraphs()) { //Loop through portions in the current Paragraph for (IPortion port : para.getPortions()) { //Display text in the current portion System.out.println(port.getText()); //Display font height of the text System.out.println(port.getPortionFormat().getFontHeight()); //Display font name of the text System.out.println(port.getPortionFormat().getLatinFont().getFontName()); } } }
還可以從整個(gè) PowerPoint 演示文稿中提取文本。以下是執(zhí)行此操作的步驟。
以下代碼示例展示了如何從 PowerPoint 演示文稿中提取文本。
//Instatiate PresentationEx class that represents a PPTX file Presentation pptxPresentation = new Presentation("presentation.pptx"); //Get an Array of ITextFrame objects from the first slide ITextFrame[] textFrames = SlideUtil.getAllTextFrames(pptxPresentation, true); //Loop through the Array of TextFrames for (int i = 0; i < textFrames.length; i++) { //Loop through paragraphs in current TextFrame for (IParagraph para : textFrames[i].getParagraphs()) { //Loop through portions in the current Paragraph for (IPortion port : para.getPortions()) { //Display text in the current portion System.out.println(port.getText()); } } }
如果你想試用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