docxcompose is a Python library for concatenating/appending Microsoft Word (.docx) files.
Append a document to another document:
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")
The docxcompose
console script allows to compose docx files from the command
line, e.g.:
$ docxcompose files/master.docx files/content.docx -o files/composed.docx
To install docxcompose for development, clone the repository and using a python with setuptools (for example a fresh virtualenv), install it using pip:
$ pip install -e .[tests]
Tests can then be run with pytest
.
The tests provide helpers for blackbox testing that can compare whole word files. To do so the following files should be provided:
The expected output can now be tested as follows:
def test_example():
fixture = FixtureDocument("expected.docx")
composed = ComposedDocument("master.docx", "slave1.docx", "slave2.docx")
assert fixture == composed
Should the assertion fail the output file will be stored in the folder docs/composed_debug with the filename of the fixture file, expected.docx in case of this example.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。