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

前端 未结 8 745
小鲜肉
小鲜肉 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:55

    We can use python-docx to keep an image on docx. docx detect image as a paragraph. But for this paragraph the text is empty. So you can use like this. paragraphs = document.paragraphs for paragraph in paragraphs: if paragraph.text == '': continue

    0 讨论(0)
  • 2021-01-02 08:00

    Are you using the docx module from here?

    If yes, then the docx module already exposes methods like replace, advReplace etc which can help you achieve your task. Refer to the source code for more details of the exposed methods.

    0 讨论(0)
提交回复
热议问题