A Python Panel application for generating personalized documents by merging Excel data with Word templates.
Document Generator allows you to:
- Upload Excel spreadsheets containing your data
- Upload one or more Word document templates
- Select specific rows to process
- Generate personalized Word documents for each selected row and template combination
- Preview generated documents as PDFs
- Download all generated documents as a ZIP file
- Python 3.8+
- LibreOffice (for PDF conversion)
- UV package manager (recommended) or pip
# Clone the repository
git clone
cd document-generator
# Install dependencies
uv sync
# or with pip:
pip install -r requirements.txtCreate a .env file in the project root:
# Path to LibreOffice executable
LIBREOFFICE_PATH=libreoffice
# PDF conversion timeout in seconds (default: 60)
CONVERSION_TIMEOUT=60# Using UV (recommended)
uv run panel serve .\src\document-generator\main.py --dev --port 5006 --static-dirs assets=".venv/Lib/site-packages/panelini/assets" --ico-path .venv/Lib/site-packages/panelini/assets/favicon.ico
# Using Python directly
python main.py
# Or with panel serve
panel serve main.py --port 5010 --devAccess the app at: http://localhost:5010
- Click "π Upload Excel Data" in the sidebar
- Select your Excel file (
.xlsxor.xls) - The data will be displayed in the Data Table
- Select rows you want to process using the checkboxes
Excel Requirements:
- First row should contain column headers
- Column names will be used as template variables
- Click "π Upload Word Templates"
- Select one or more Word documents (
.docx) - Each template appears in the Templates Configuration table
- Customize the Naming Template for output files (optional)
In the Templates Configuration table, edit the Naming Template column to customize output filenames.
Syntax:
prefix_{{ column_name }}_suffix
Example:
Invoice_{{ Customer_ID }}_{{ Year }}
For a row with Customer_ID=12345 and Year=2024, generates:
Invoice_12345_2024.docx
- Select rows in the Data Table (checkboxes)
- Click "Preview PDFs"
- PDFs appear in the PDF Previews section
- Review before downloading
- Select rows to process
- Click "Download Word Files (ZIP)"
- A ZIP file containing all Word documents will download
Document Generator uses python-docx-template syntax.
In your Word template, use double curly braces:
Dear {{ Customer_Name }},
Your invoice number is {{ Invoice_Number }}.
Total: {{ Amount }} EUR
Variable names must not contain spaces or special characters except underscores.
Column names will automatically be converted to valid variable names by replacing spaces with underscores and removing special characters.
The status message on the left will inform you of any changes made to column names and which names to use in your templates.

Conditional Content:
{% if Premium_Customer %}
Thank you for being a premium customer!
{% endif %}
Formatting:
Date: {{ Date | date_format }}
Amount: {{ Amount | currency }}
Excel Column Matching:
- Template variable names must exactly match Excel column names (case-sensitive)
- Spaces in column names are preserved:
{{ First Name }} - Leading/trailing whitespace is automatically trimmed
| Component | Technology | Relevant Links |
|---|---|---|
| UI Framework | Panel | Panel Official Documentation |
| Template Engine | python-docx-template | Python-Docx-Template Documentation |
| Excel Parsing | pandas, openpyxl | Pandas Documentation, OpenPyXL Documentation |
| PDF Conversion | LibreOffice (headless) | LibreOffice Official Documentation |
| App Framework | Panelini | Panelini GitHub Repository |
- Batch Processing: Generate multiple documents in one operation
- Multi-template Support: Process multiple templates simultaneously
- Real-time Preview: View PDFs before downloading
- Flexible Naming: Customize output filenames with template variables
- Row Selection: Process only the data you need
- Error Handling: Clear error messages and notifications
| Variable | Description | Default |
|---|---|---|
LIBREOFFICE_PATH |
Path to LibreOffice executable | libreoffice |
CONVERSION_TIMEOUT |
PDF conversion timeout (seconds) | 60 |
Error: LibreOffice conversion failed
Solution:
- Install LibreOffice: https://www.libreoffice.org/download/
- Update
LIBREOFFICE_PATHin.envwith the correct path - Test manually:
libreoffice --version
Problem: Variables show as {{ Variable_Name }} in output
Solution:
- Ensure Excel column names exactly match template variables
- Check for extra spaces in column names
- Variable names are case-sensitive
Problem: PDF preview fails or times out
Solution:
- Increase
CONVERSION_TIMEOUTin.env - Ensure LibreOffice is not running in normal mode
- Check system resources (CPU/memory)
Problem: Error loading Excel file
Solution:
- Ensure file is valid
.xlsxor.xlsformat - Check for merged cells (may cause issues)
- Verify first row contains headers
- Uploaded files are processed in temporary directories
- Temporary files are automatically cleaned up
- No data is persisted after session ends
- Run behind authentication in production environments
This project is licensed under the Apache License 2.0.
See the LICENSE file for details or visit: https://www.apache.org/licenses/LICENSE-2.0
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure your code follows the existing style and includes appropriate tests.
For questions or issues, please open an issue on GitHub.
