python docx用保存样式替换字符串

python docx用保存样式替换字符串,python,ms-word,python-docx,Python,Ms Word,Python Docx,在字符串替换过程中是否有保存段落样式的方法 from docx import Document doc = Document('source.docx') for p in doc.paragraphs: if 'some text' in p.text: text = p.text.replace('some text', 'new text') style = p.style p.text = text p.styl

在字符串替换过程中是否有保存段落样式的方法

from docx import Document


doc = Document('source.docx')
for p in doc.paragraphs:
    if 'some text' in p.text:
        text = p.text.replace('some text', 'new text')
        style = p.style
        p.text = text
        p.style = style

doc.save('dest.docx')
此代码替换字符串,但更改字体样式和背景颜色