Ich möchte mit dem Python-pptx-Modul die Proofing-Sprache jeder texthaltigen Form in einer Powerpoint-Präsentation ändern. Leider schaffe ich es nicht. :(python-pptx - set proofing language
Ich verwende Python 3.6.3 und Python-pptx 0.6.7
Mein Code sieht wie folgt aus:.!
from pptx import Presentation
from pptx.enum.lang import MSO_LANGUAGE_ID
# In this example code, all proofing language is set to ENGLISH_UK
# all languages can be found in the docs for python-pptx
new_language = MSO_LANGUAGE_ID.ENGLISH_UK
input_file = 'test_pptx.pptx'
output_file = input_file[:-5] + '_modified.pptx'
# Open the presentation
prs = Presentation(input_file)
# iterate through all slides
for slide_no, slide in enumerate(prs.slides):
# iterate through all shapes/objects on one slide
for shape in slide.shapes:
# check if the shape/object has text (pictures e.g. don't have text)
if shape.has_text_frame:
# print some output to the console for now
print('SLIDE NO# ', slide_no + 1)
print('Object-Name: ', shape.name)
print('Text -->', shape.text)
# check for each paragraph of text for the actual shape/object
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
# display the current language
print('Actual set language: ', run.font.language_id)
# set the 'new_language'
run.font.language_id = new_language
else:
print('SLIDE NO# ', slide_no + 1, ': This object "', shape.name, '" has no text.')
print(' +++++ next element +++++ ')
print('--------- next slide ---------')
# save pptx with new filename
prs.save(output_file)
Dieser Code funktioniert jetzt (wieder, dank Steve !)
Bitte helfen! Vielen Dank im Voraus!
Hey Steve! Das war genau das fehlende Teil in meinem Puzzle. Jetzt funktioniert es. Ich werde meinen Code auffrischen und ich werde es hier posten! Danke vielmals! – ChristianH