Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ThibaudLamothe/0346444dae8685fcc289c0f9c74e807c to your computer and use it in GitHub Desktop.
Save ThibaudLamothe/0346444dae8685fcc289c0f9c74e807c to your computer and use it in GitHub Desktop.
Replacing the text of a ppt text frame without changing it's font parameters
# For each paragraph of each text_frame
for text_frame in all_presentation_text_frames:
for paragraph in text_frame.paragraphs:
# We get the translated text
old_text = text_frame.paragraphs[idx].text
new_text = corpus_translated[old_text]
# And inspect the runs (for font analysis)
if len(paragraph.runs)>0:
# If there is a run : we replace text without changing the font
p = paragraph._p
for idx, run in enumerate(paragraph.runs):
if idx == 0:
continue
p.remove(run._r)
paragraph.runs[0].text = new_text
# If no runs, we can modify the text directly
else:
text_frame.paragraphs[idx].text = new_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment