Skip to main content

Compose .docx documents

Project description

docxcompose is a Python library for concatenating/appending Microsoft Word (.docx) files.

Example usage

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

The docxcompose console script allows to compose docx files form the command line, e.g.:

$ docxcompose files/master.docx files/content.docx -o files/composed.docx

A note about testing

The tests provide helpers for blackbox testing that can compare whole word files. To do so the following files should be provided:

  • a file for the expected output that should be added to the folder docs/composed_fixture

  • multiple files that can be composed into the file above should be added to the folder docs.

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.

Changelog

1.0.0 (2019-06-13)

  • Change license from GPL to MIT. [buchi]

  • Add support for adding, setting and deleting of doc properties. [buchi]

1.0.0a17 (2019-04-25)

  • Add functionality to get and set content of plain text content controls (structured document tags). [buchi]

1.0.0a16 (2019-01-15)

  • Prevent artifacts of previously cached doc property values during update. [deiferni]

1.0.0a15 (2018-12-12)

  • Fix updating doc-properties with non-ascii names. [deiferni]

  • Don’t handle hyperlink references twice. [deiferni]

1.0.0a14 (2018-12-04)

  • Implement generic handling of referenced parts. Among other, this adds support for embedded Excel charts. [buchi]

  • Handle embedded SVGs. [buchi]

  • Add styles from other parts, e.g. footnotes. [buchi]

1.0.0a13 (2018-11-05)

  • Fix list-styles being set incorrectly when restarting numberings. [deiferni]

1.0.0a12 (2018-10-30)

  • Fix setting section type for appended documents with only one section. [deiferni]

1.0.0a11 (2018-07-30)

  • Fix handling of section type. [buchi]

  • Fix an issue where the listing style of the first element was different. [deiferni]

  • Fix issue when restarting intermittent numbering. [deiferni]

1.0.0a10 (2018-07-18)

  • Add console script command to compose two or more word files. [deiferni]

1.0.0a9 (2018-05-01)

  • Fix error in mapping of num_ids introduced in 1.0.0.a7. [buchi]

  • Do not fail when numbering zero is referenced. [deiferni]

1.0.0a8 (2018-04-26)

  • Only attempt to set the nsid when it is available. [deiferni]

1.0.0a7 (2018-04-20)

  • Fix handling of images in WordprocessingGroups (<wpg:wpg>). [buchi]

  • Fix handling of shapes in shape groups (<v:group>). [buchi]

  • Fix handling of numberings, avoid inserting multiple numbering properties. [buchi]

  • Fix renumbering of bookmarks. [buchi]

  • Renumber ids of drawing object properties (<wp:docPr>). [buchi]

1.0.0a6 (2018-02-20)

  • Do not restart numbering of bullets. [buchi]

1.0.0a5 (2018-01-11)

  • Renumber bookmarks to avoid duplicate ids. [buchi]

  • Add support for shapes. [buchi]

1.0.0a4 (2017-12-27)

  • Fix handling of styles when composing documents with different languages. [buchi]

  • Also add numberings referenced in styles. [buchi]

  • Avoid having multiple <w:abstractNum> elements for the same style. [buchi]

  • Restart first numbering of inserted documents [buchi]

  • Add support for anchored images. [buchi]

  • Handle referenced style ids that are not defined in styles.xml [buchi]

  • Remove header and footer references in paragraph properties. [buchi]

1.0.0a3 (2017-11-22)

  • Make removal of property fields optional. [buchi]

1.0.0a2 (2017-11-06)

  • Fix handling of footnotes containing hyperlinks. [buchi]

  • Add functionality to deal with custom document properties. Properties can be updated and fields containing properties can be removed. When appending or inserting documents their custom document properties get removed automatically. [buchi]

1.0.0a1 (2017-09-13)

  • Initial release [buchi]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docxcompose-1.0.0.tar.gz (14.5 kB view details)

Uploaded Source

File details

Details for the file docxcompose-1.0.0.tar.gz.

File metadata

  • Download URL: docxcompose-1.0.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/7.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.16

File hashes

Hashes for docxcompose-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2a9a12e24270c3612567d42fdcc6bbbd8a27b10f689ddc9f8ec1b84cc0ae07be
MD5 b01362ed367e90c8cabac468cbe2a808
BLAKE2b-256 1a07f6278b5d96656f84e6b66b71cb3485879951cb8478d131b4082138aea60d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page