Giter Site home page Giter Site logo

docxcompose's Introduction

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 from the command line, e.g.:

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

Installation for development

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.

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.

Headers and footers

The first document is considered as the main template and headers and footers from the other documents are ignored, so that the header and footer of the first document is used throughout the merged file.

docxcompose's People

Contributors

brycestevenwilley avatar buchi avatar danmaps avatar deiferni avatar inujel avatar lonetwin avatar lukasgraf avatar tyrin451 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.