Skip to main content

Fill text and images into .docx files from placeholders.

Project description

📝 DOCX Placeholder Filler (with Image and Embedded Excel Support)

Description

This Python tool automatically replaces placeholders in Microsoft Word .docx documents with text, images, or data from embedded Excel files. It's ideal for generating templates like contracts, certificates, reports, and dynamic documents.


✨ Features

  • 🔤 Replace text placeholders in .docx files
  • 🖼️ Insert images into Word using placeholders
  • 📊 Modify embedded Excel files (.xlsx) that used to generate plot, chart or anything else inside Word documents
  • 🧩 Supports placeholders inside textboxes
  • 🧾 Detect unfilled placeholders
  • ✅ Preserve existing comments in .docx documents
  • 🧠 Smart parsing of complex or multiline placeholder structures

📦 Installation

pip install docxfill

🧱 Placeholder Format

Type Syntax Example Replacement Type
Text {{name}} String
Number {{age}} Int / Float
Image {{profile_picture}} Image path
Excel {{invoice_total}} (in cell) Cell content

🚀 Usage

1. Run execute()

from docxfill.fill import execute

result = execute(
    file_path="template.docx",             # Input .docx file
    output_file_path="output.docx",        # Output .docx file
    text_content={"name": "John", "age": "30"},
    image_content={"profile_picture": "images/photo.jpg"},
    state_dir="./test_files"               # Optional working directory
)

print(result)

2. Sample Output

{
  "tool": "docx_fill_with_image",
  "success": true,
  "output_file_path": "output.docx",
  "filled": {
    "name": "John",
    "age": "30",
    "profile_picture": "images/photo.jpg"
  },
  "unfilled_placeholder": ["email", "address"]
}

🔍 Key Functions

Function Description
replace_text_in_paragraph() Replace text in regular paragraphs
replace_text_in_excel_sheet() Replace text inside Excel cells
extract_and_modify_embedded_excel() Modify embedded .xlsx content
find_inner_placeholders_in_docx() Find any unfilled placeholders
execute() Main function to run all processes
✅ Supports placeholder inside Word textboxes

📁 Folder Structure Example

test_files/
├── template.docx
├── output.docx
└── images/
    └── photo.jpg

⚠️ Notes

  • Only supports .docx (not .doc)
  • Embedded Excel files must be .xlsx format
  • Placeholders must follow the {{placeholder}} format
  • Images must be valid paths (relative or absolute)

📄 License

MIT License — Free for personal and commercial use.

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

docxfill-1.0.7.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docxfill-1.0.7-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file docxfill-1.0.7.tar.gz.

File metadata

  • Download URL: docxfill-1.0.7.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for docxfill-1.0.7.tar.gz
Algorithm Hash digest
SHA256 55d7702015d507de5890d3df74e0ca55530234f80bb4c8387bf5db9c97168335
MD5 86150f9d4203876a3c919308ade32d88
BLAKE2b-256 be415c163d424bd68de058cc7b144cf5185b7159525189aa85ec8ef809ddd943

See more details on using hashes here.

Provenance

The following attestation bundles were made for docxfill-1.0.7.tar.gz:

Publisher: publish.yml on littlenys/docxfill

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docxfill-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: docxfill-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for docxfill-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 14091f12cb54473d7b10fff88e003f9a31972f919c20739540fef0b0aaf2d43b
MD5 d77ddfa919315cb4e36dd2a919f04336
BLAKE2b-256 c8f6a4a712105ffa17271127505770efe828266b12b289e25e0a231e65128cf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for docxfill-1.0.7-py3-none-any.whl:

Publisher: publish.yml on littlenys/docxfill

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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