/python-pptx-sample.py Secret
Created
March 15, 2022 13:49
python-pptxの使用例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pptx | |
def pptx2text(file_path): | |
texts = [] # 抽出したテキストデータを格納する空リスト | |
prs = pptx.Presentation(file_path) | |
# スライドごとにテキストデータを抽出する | |
for sld in prs.slides: | |
for shape in sld.shapes: | |
# shapeに含まれるテキストデータを抽出 | |
if shape.has_text_frame: | |
for text in shape.text.splitlines(): | |
texts.append(text) | |
# tableに含まれるテキストデータを抽出 | |
if shape.has_table: | |
for cell in shape.table.iter_cells(): | |
for text in cell.text.splitlines(): | |
texts.append(text) | |
return texts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment