国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python 實(shí)現(xiàn)提取PPT中所有的文字

瀏覽:5日期:2022-06-26 08:07:31

我就廢話不多說(shuō)了,大家還是直接看代碼吧~

# 導(dǎo)入pptx包from pptx import Presentationprs = Presentation(path_to_presentation)text_runs = []for slide in prs.slides: for shape in slide.shapes: if not shape.has_text_frame: continue for paragraph in shape.text_frame.paragraphs: for run in paragraph.runs: text_runs.append(run.text)

補(bǔ)充:使用 python-pptx-interface 將PPT轉(zhuǎn)換成圖片

?00 簡(jiǎn)單方法

最簡(jiǎn)單的方法就是使用PPTX的File中的SaveAs命令,將PPTX文件另存為JPEG格式。

python 實(shí)現(xiàn)提取PPT中所有的文字

▲ 使用PPT的SaveAs將PPTX存儲(chǔ)為JPEG

注意,在最后一步的時(shí)候需要選擇“所有幻燈片(A)”。

python 實(shí)現(xiàn)提取PPT中所有的文字

▲ 選擇所有幻燈片

最后,PPTX的每張幻燈片都以獨(dú)立文件方式保存到文件中。X

這部分的內(nèi)容可以參照: How to Export PowerPoint Slides as JPG or Other Image Formats 中的介紹。

?01 使用Python-PPTX1.簡(jiǎn)介

python-pptx是用于創(chuàng)建和更新PointPoint(PPTX)文件的Python庫(kù)。

一種常用的場(chǎng)合就是從數(shù)據(jù)庫(kù)內(nèi)容生成一個(gè)客戶定制的PointPoint文件,這個(gè)過(guò)程通過(guò)點(diǎn)擊WEB應(yīng)用上的連接完成。許多開(kāi)發(fā)之 通過(guò)他們?nèi)粘9芾硐到y(tǒng)生成工程狀態(tài)匯報(bào)PPT。它也可以用于批量生成PPT或者產(chǎn)品特性說(shuō)明PPT。

python-ppt License:

The MIT License (MIT) Copyright © 2013 Steve Canny, https://github.com/scanny

Python-PPTX對(duì)應(yīng)的官方網(wǎng)絡(luò)網(wǎng)址: Python-PPTX https://python-pptx.readthedocs.io/en/latest/user/intro.html#

2.安裝

使用pip進(jìn)行安裝:

pip install python-pptx

對(duì)于python要求: Python2.7,3.3,3.4,3.6

依賴庫(kù):

Python 2.6, 2.7, 3.3, 3.4, or 3.6lxmlPillowXlsxWriter (to use charting features)?02 測(cè)試

下面的例子來(lái)自于: Get Start 。

1. Hello Word

from pptx import Presentationprs = Presentation()title_slide_layout = prs.slide_layouts[0]slide = prs.slides.add_slide(title_slide_layout)title = slide.shapes.titlesubtitle = slide.placeholders[1]title.text = ’Hello world!’subtitle.text = ’python-pptx was here.’prs.save(r’d:temptest.pptx’)printf('a')

python 實(shí)現(xiàn)提取PPT中所有的文字

2.Add_TextBox

from pptx import Presentationfrom pptx.util import Inches, Ptprs = Presentation()blank_slide_layout = prs.slide_layouts[6]slide = prs.slides.add_slide(blank_slide_layout)left = top = width = height = Inches(1)txBox = slide.shapes.add_textbox(left, top, width, height)tf = txBox.text_frametf.text = 'This is text inside a textbox'p = tf.add_paragraph()p.text = 'This is a second paragraph that’s bold'p.font.bold = Truep = tf.add_paragraph()p.text = 'This is a third paragraph that’s big'p.font.size = Pt(40)prs.save(r’d:temptest1.pptx’)

python 實(shí)現(xiàn)提取PPT中所有的文字

?03 輸出JPEG1.安裝 python-pptx-interface

pip install python-pptx-interface2.轉(zhuǎn)換PPTX

注意:轉(zhuǎn)換生成的目錄必須使用新的目錄。否則就會(huì)出現(xiàn):

Folder d:temppptimage already exists. Set overwrite_folder=True, if you want to overwrite folder content.

from pptx_tools import utilspptfile = r’D:Temp如何搭建自己的電子實(shí)驗(yàn)室_20210102R10.pptx’png_folder = r’d:temppptimage’utils.save_pptx_as_png(png_folder, pptfile, overwrite_folder=True)

生成后的PPT對(duì)應(yīng)的PNGImage。

python 實(shí)現(xiàn)提取PPT中所有的文字

▲ 生成后的PPTX對(duì)應(yīng)的PNG圖片

※ 結(jié)論

將PPTX轉(zhuǎn)換成圖片,可以便于后期將文件上載到CSDN,或者用于DOP文件的制作。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

標(biāo)簽: python
相關(guān)文章:
主站蜘蛛池模板: 息烽县| 南平市| 山西省| 铜川市| 娄烦县| 招远市| 株洲县| 浮梁县| 棋牌| 新巴尔虎右旗| 孝义市| 依安县| 精河县| 东丰县| 新民市| 沅陵县| 青阳县| 磴口县| 五华县| 伊吾县| 洪雅县| 玉门市| 宜丰县| 易门县| 富平县| 太谷县| 闽侯县| 扬州市| 崇义县| 当涂县| 永定县| 抚州市| 喀什市| 芦山县| 通州区| 富顺县| 原平市| 杨浦区| 思茅市| 石景山区| 安吉县|