Created
September 16, 2023 14:43
-
-
Save krid78/286478033f37725ceb1aeae2fb62affc to your computer and use it in GitHub Desktop.
Analyze pptx using 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
__SRC_PATH__ = "foo/" | |
__SRC_NAME__ = "bar.pptx" | |
def main(): | |
"""The main function""" | |
prs = Presentation(f"{__SRC_PATH__}{__SRC_NAME__}") | |
for sl_idx,slide in enumerate(prs.slides): | |
print(f"--- Slide {sl_idx} --- slide_layouts[{prs.slide_layouts.index(slide.slide_layout)}]: \"{slide.slide_layout.name}\"") | |
print(f"--- Slide {sl_idx} --- Placeholders ---") | |
for ph_idx,ph in enumerate(slide.placeholders): | |
print(f"\tplaceholders[{ph_idx}]:") | |
print(f"\t\tname: {ph.name}, shape_type: {ph.shape_type}") | |
print(f"\t\tph type: {ph.placeholder_format.type}") | |
if ph.has_text_frame: | |
print(f"\t\ttext_frame: {ph.text_frame}") | |
print(f"\t\ttext: {ph.text}") | |
for lidx,line in enumerate(ph.text_frame.paragraphs): | |
print(f"{line.level}; {line.text}") | |
print(f"--- Slide {sl_idx} --- Shapes ---") | |
for sh_idx,sh in enumerate(slide.shapes): | |
print(f"\tshapes[{sh_idx}]:") | |
print(f"\t\tname: {sh.name}, shape_type: {sh.shape_type}") | |
if sh.is_placeholder: | |
print(f"\t\tsh is ph of type: {sh.placeholder_format.type}") | |
if sh.has_text_frame: | |
print(f"\t\ttext_frame: {sh.text_frame}") | |
print(f"\t\ttext: {sh.text}") | |
for lidx,line in enumerate(sh.text_frame.paragraphs): | |
print(f"{line.level}; {line.text}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment