I'd like to update the text within a textbox without changing the formatting. In other words, I'd like to keep the original formatting of the original text while changing that text
I can update the text with the following, but the formatting is changed completely in the process.
from pptx import Presentation
prs = Presentation("C:\\original_powerpoint.pptx")
sh = prs.slides[0].shapes[0]
sh.text_frame.paragraphs[0].text = 'MY NEW TEXT'
prs.save("C:\\new_powerpoint.pptx")
How can I update the text while maintaining the original formatting?
I've also tried the following:
from pptx import Presentation
prs = Presentation("C:\\original_powerpoint.pptx")
sh = prs.slides[0].shapes[0]
p = sh.text_frame.paragraphs[0]
original_font = p.font
p.text = 'NEW TEXT'
p.font = original_font
However I get the following error:
Traceback (most recent call last):
File "C:\Codes\powerpoint_python_script.py", line 24, in <module>
p.font = original_font
AttributeError: can't set attribute