Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xltemplate-0.2.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

xltemplate-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file xltemplate-0.2.0.tar.gz.

File metadata

  • Download URL: xltemplate-0.2.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xltemplate-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c9f536b9854b90ee61fa2e325ea1ced931b96348dba38709f3928af6ee326df1
MD5 313372b2cfd7f558a2a10c628dbe9f3d
BLAKE2b-256 aad500ecc9703785831df70b2745416eb0badead57d6e6523fc78dab2dade9a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for xltemplate-0.2.0.tar.gz:

Publisher: publish.yml on mostlyunoriginal/xltemplate

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

File details

Details for the file xltemplate-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: xltemplate-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xltemplate-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 312f6e5c67e248c3fd0828e888849809a6818ac8088018960b350eb9e8aca48c
MD5 9548077bd861906e1820949110cc39a7
BLAKE2b-256 4986347325ee28e85f290b8456dea2de1a5f4f3df61cf36e6756e20830262982

See more details on using hashes here.

Provenance

The following attestation bundles were made for xltemplate-0.2.0-py3-none-any.whl:

Publisher: publish.yml on mostlyunoriginal/xltemplate

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