如何使用 python 将包含超链接 .docx 的文档合并到另一个 .docx?

how can i merge a document containing hyperlinks .docx to an other .docx using python?

我找到了这个解决方案 combine word document using python docx 有人说:

If you just need to combine simple documents with only text, you can use python-docx as mentioned above.

如果您需要合并包含超链接、图像、列表、项目符号等的文档。您可以使用 lxml 合并文档正文和所有参考文件,例如:

word/styles.xml word/numbering.xml word/media [Content_Types].xml" 如果他看到这个我希望他能详细说明一点 无论如何,我想将一个 .docx 合并到另一个 .docx,一个简单的合并,将 word 文档的内容添加到另一个文档的最后一页,该文档可以包含文本、图像、表格......所有你可以的超链接想象一下,只是抓取一个文档的内容放到另一个文档中,但是我找不到答案。

试试 docxcompose。

https://pypi.org/project/docxcompose/

此代码创建一个添加 doc1 的主文档。

from docxcompose.composer import Composer
from docx import Document
master = Document("master.docx")
composer = Composer(master)
doc1 = Document("doc1.docx")
composer.append(doc1)
composer.save("combined.docx")

比如你还想添加doc2,可以在第六行之后添加:

doc2 = Document("doc2.docx")
composer.append(doc2)