A clean OOP interface for populating Excel templates with DataFrames
Project description
xltemplate
A lightweight Python wrapper around openpyxl that provides a clean, stateful OOP interface for populating Excel templates with DataFrames while preserving formatting.
Installation
pip install xltemplate # Core only
pip install xltemplate[pandas] # With Pandas support
pip install xltemplate[polars] # With Polars support
pip install xltemplate[all] # With both
Quick Start
from xltemplate import Workbook
import pandas as pd
# Load an existing template
wb = Workbook("template.xlsx")
# Write a DataFrame starting at row 5, column 2
df = pd.DataFrame({"Name": ["Alice", "Bob"], "Score": [95, 87]})
wb.sheet("Summary").write_df(df, row=5, col=2)
# Save to a new file
wb.save("output.xlsx")
Features
- First-class Pandas & Polars support — Pass either DataFrame type to
write_df() - Format preservation — Existing cell styles are preserved by default
- Formula preservation — Cells containing formulas are skipped by default
- Clean API — Stateful, chainable methods inspired by R's openxlsx
API Reference
Workbook
wb = Workbook("template.xlsx") # Load existing workbook
wb.sheet("SheetName") # Get Sheet object
wb.sheet_names # List all sheet names
wb.save("output.xlsx") # Save to file
Sheet
sheet = wb.sheet("Data")
# Write DataFrame
sheet.write_df(
df,
row=1, # Starting row (1-indexed)
col=1, # Starting column (1-indexed)
headers=True, # Include column headers (default: True)
preserve_format=True, # Keep existing cell formatting (default: True)
preserve_formulas=True # Skip cells with formulas (default: True)
)
# Write single value
sheet.write_value("Hello", row=1, col=1)
# Get sheet name
sheet.name
License
MIT
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 xltemplate-0.1.0.tar.gz.
File metadata
- Download URL: xltemplate-0.1.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8926b3b4874adfc1856d04c924c867a312bef0e8aea37cf030ca0dae19ca48e8
|
|
| MD5 |
99bcd46175cfe57ad143a0e637092d0f
|
|
| BLAKE2b-256 |
234c014b0e2c64e92c58ba945fd0ba569629625fbc17eebc5d4c7d3f2925e274
|
Provenance
The following attestation bundles were made for xltemplate-0.1.0.tar.gz:
Publisher:
publish.yml on mostlyunoriginal/xltemplate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xltemplate-0.1.0.tar.gz -
Subject digest:
8926b3b4874adfc1856d04c924c867a312bef0e8aea37cf030ca0dae19ca48e8 - Sigstore transparency entry: 832931481
- Sigstore integration time:
-
Permalink:
mostlyunoriginal/xltemplate@193ca88c04d95d4adf82502d2e7f4b812a42f983 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mostlyunoriginal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@193ca88c04d95d4adf82502d2e7f4b812a42f983 -
Trigger Event:
release
-
Statement type:
File details
Details for the file xltemplate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xltemplate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b0930748c9b56d0df238836b6da8622ee47a91a2ffb8110d038c2c4f6e8a243
|
|
| MD5 |
f64c54450937d3aad1267709ad527f74
|
|
| BLAKE2b-256 |
cddf036673d2f28a6a976f0ae5f0d3e80f888e892d3dcc3262acc5ee5ab11a04
|
Provenance
The following attestation bundles were made for xltemplate-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on mostlyunoriginal/xltemplate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xltemplate-0.1.0-py3-none-any.whl -
Subject digest:
4b0930748c9b56d0df238836b6da8622ee47a91a2ffb8110d038c2c4f6e8a243 - Sigstore transparency entry: 832931482
- Sigstore integration time:
-
Permalink:
mostlyunoriginal/xltemplate@193ca88c04d95d4adf82502d2e7f4b812a42f983 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mostlyunoriginal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@193ca88c04d95d4adf82502d2e7f4b812a42f983 -
Trigger Event:
release
-
Statement type: