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
.docxfiles - 🖼️ 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
.xlsxformat - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55d7702015d507de5890d3df74e0ca55530234f80bb4c8387bf5db9c97168335
|
|
| MD5 |
86150f9d4203876a3c919308ade32d88
|
|
| BLAKE2b-256 |
be415c163d424bd68de058cc7b144cf5185b7159525189aa85ec8ef809ddd943
|
Provenance
The following attestation bundles were made for docxfill-1.0.7.tar.gz:
Publisher:
publish.yml on littlenys/docxfill
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docxfill-1.0.7.tar.gz -
Subject digest:
55d7702015d507de5890d3df74e0ca55530234f80bb4c8387bf5db9c97168335 - Sigstore transparency entry: 268553722
- Sigstore integration time:
-
Permalink:
littlenys/docxfill@4a8287cf24256c6c9e4049969c54175b978afc4d -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/littlenys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4a8287cf24256c6c9e4049969c54175b978afc4d -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14091f12cb54473d7b10fff88e003f9a31972f919c20739540fef0b0aaf2d43b
|
|
| MD5 |
d77ddfa919315cb4e36dd2a919f04336
|
|
| BLAKE2b-256 |
c8f6a4a712105ffa17271127505770efe828266b12b289e25e0a231e65128cf4
|
Provenance
The following attestation bundles were made for docxfill-1.0.7-py3-none-any.whl:
Publisher:
publish.yml on littlenys/docxfill
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docxfill-1.0.7-py3-none-any.whl -
Subject digest:
14091f12cb54473d7b10fff88e003f9a31972f919c20739540fef0b0aaf2d43b - Sigstore transparency entry: 268553728
- Sigstore integration time:
-
Permalink:
littlenys/docxfill@4a8287cf24256c6c9e4049969c54175b978afc4d -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/littlenys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4a8287cf24256c6c9e4049969c54175b978afc4d -
Trigger Event:
push
-
Statement type: