Skip to content

A Python tool to generate Word documents by replacing placeholders in .docx templates with values from an Excel file.

License

Notifications You must be signed in to change notification settings

DrBlink7/docx-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docx-mapper

This is a simple script that takes a Word document template and an Excel file with values to replace placeholders, and generates a finalized document with the data filled in.

🧾 What it does

  • Reads base_document.docx, which contains placeholders like {{company}}, {{first_name}}, etc.
  • Loads mapping.xlsx, which contains the field names and the values to replace.
  • Outputs a new file final_document.docx with all placeholders replaced.

🐳 Prerequisites

🗂️ Folder structure

Here is the folder structure for the project:

project_root/
├── backend/                # Contains the main application files
│   ├── base_document.docx  # Word template with placeholders
│   ├── mapping.xlsx        # Excel file with placeholder values
│   ├── script.py           # Main script for processing
│   ├── Dockerfile          # Docker configuration for the backend
│   ├── requirements.txt    # Python dependencies
├── LICENSE                 # License file for the project
├── README.md               # Documentation for the project
└── docker-compose.yml      # Docker Compose configuration

🛠️ How to use

  1. Place your Word template (base_document.docx) and Excel file (mapping.xlsx) in the root folder.
  2. Open a terminal and run:
docker compose up --build
  1. The output file final_document.docx will be generated in the same folder.

⚙️ Optional settings

The script accepts a flag called USE_DATETIME that determines how Excel date fields are formatted:

  • True → formats dates as dd/mm/yyyy (e.g., 01/01/1980)
  • False (default) → keeps the full datetime (e.g., 01/01/1980 00:00:00)

To enable this option, edit the script.py and set:

USE_DATETIME = False

🧪 Example

Given this placeholder in the Word file:

{{name}} was born on {{born_in}}

And the following Excel content:

A             B
name          Mario Rossi
born_in       01/01/1980

You will get this result:

Mario Rossi was born on 01/01/1980

About

A Python tool to generate Word documents by replacing placeholders in .docx templates with values from an Excel file.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published