Text-Replace in docx and save the changed file with python-docx

前端 未结 8 814
小鲜肉
小鲜肉 2021-01-02 07:04

I\'m trying to use the python-docx module to replace a word in a file and save the new file with the caveat that the new file must have exactly the same formatting as the ol

8条回答
  •  悲&欢浪女
    2021-01-02 07:43

    The problem with the methods above is that they lose the existing formatting. Please see my answer which performs the replace and retains formatting.

    There is also python-docx-template which allows jinja2 style templating within a docx template. Here's a link to the documentation

提交回复
热议问题