How to use python-docx to replace text in a Word document and save

后端 未结 7 1934
后悔当初
后悔当初 2020-11-29 19:25

The oodocx module mentioned in the same page refers the user to an /examples folder that does not seem to be there.
I have read the documentation of python-docx 0.7.2, p

7条回答
  •  遥遥无期
    2020-11-29 20:13

    For the table case, I had to modify @scanny's answer to:

    for table in doc.tables:
        for col in table.columns:
            for cell in col.cells:
                for p in cell.paragraphs:
    

    to make it work. Indeed, this does not seem to work with the current state of the API:

    for table in document.tables:
        for cell in table.cells:
    

    Same problem with the code from here: https://github.com/python-openxml/python-docx/issues/30#issuecomment-38658149

提交回复
热议问题