WolfSDKWolfXLWolfPPTWolfDocxWolfRender

WolfDocx documentation - Commercial

Merge existing DOCX files in Python with explicit style policy

WolfDocx Commercial merges existing DOCX files with merge_docx and publishes a new package. The first input supplies the destination document, and later inputs are imported in order under an explicit formatting policy. This document-assembly API requires the authenticated Commercial installation, not the public Community package.

Install Commercial separately

Use the commercially licensed wolfdocx installation from its authenticated package index. Configure pip with the credential from the checkout success page before running the bash or zsh command below. Keep this environment separate from Community because both editions install under the name wolfdocx from different indexes.

python -m pip install wolfdocx --index-url https://packages.wolfxl.com/wolfdocx/simple/

The public pip install wolfdocx path is for Community editing of existing files. It is not the installation for this merge API. Likewise, merging documents is not mail merge: assembly combines document content, whereas mail merge populates a template once for each recipient record.

Merge two reviewed documents

Prepare cover.docx and body.docx, then run this Python in the Commercial environment. The parent directory for combined.docx must exist, and the destination must be absent. Re-running the same script against an occupied output is expected to refuse instead of overwriting it.

import json
from wolfdocx import ImportFormatMode, merge_docx

report = merge_docx(
    ["cover.docx", "body.docx"],
    "combined.docx",
    format_mode=ImportFormatMode.KEEP_SOURCE_FORMATTING,
)
if not report.passed:
    raise SystemExit(report.code)
print(json.dumps(report.to_dict(), indent=2))

The order is meaningful. The first package is the destination context; it is not merely the first string in a text concatenation. Incoming content can reference styles, numbering, images, headers, and other package dependencies. Copying body XML without moving its relationships is not equivalent to importing a document.

The assembly implementation relocates supported dependencies and identities through its importer. Unsupported body content can refuse the operation instead of disappearing silently. This is why the sample checks report.passed rather than assuming that returning a report means a usable document was published.

Choose the style collision policy

ImportFormatModePolicy
KEEP_SOURCE_FORMATTINGKeep source formatting; this is the default mode.
USE_DESTINATION_STYLESUse destination styles when importing content.
KEEP_DIFFERENT_STYLESRetain differing source styles rather than treating every name collision alike.

Choose based on the reviewed documents and the intended result. A house-style report may need destination styles; an appendix assembled from independently authored documents may need source formatting. No single policy is a promise that the output will occupy the same number of pages as the inputs.

The format_options argument supplies the engine's ImportFormatOptions for more detailed import policy. This introductory example deliberately leaves those defaults intact. Do not invent option names from another Word library: use the Commercial source-backed API reference when selecting additional controls.

Handle publication as part of the operation

merge_docx binds admitted inputs to their source bytes and publishes without replacing a destination. The report includes source receipts. Keep that report alongside the output when your application needs to explain which packages were assembled and whether the operation actually published.

A refusal is a boundary, not evidence that removing the offending document's XML would be safe. Check the code, inspect the relevant source structure, and choose an explicitly supported path. For revision-heavy or active-content documents, do not assume package-level assembly accepts every structure that can be displayed by Word.

What it does not do

  • It does not provide document assembly through Community 0.1.0.
  • It does not concatenate plain text while discarding package dependencies.
  • It does not guarantee identical Microsoft Word layout or unchanged pagination.
  • It does not render a PDF, refresh every field cache, or populate recipient data.

Related workflows

See the document-merge task guide, recipient mail merge, and refreshing fields after editing.

Get WolfDocx

WolfDocx Community is MIT-licensed and free, including commercial use. It edits existing .docx files in place in pure Python and does not render pages or convert to PDF. WolfDocx Commercial does not change those rights.

pip install wolfdocx

WolfDocx Commercial is an organization-scoped subscription. WolfDocx Community installs from public PyPI with pip install wolfdocx. WolfDocx Commercial installs from the authenticated WolfDocx package index with a per-purchase credential, issued on the checkout success page after payment and reissued through https://wolfxl.com/recover.

Review the scoped before-and-after memo files in the reporting walkthrough, or ask about your document before purchasing if compatibility is uncertain.

Related tasks