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.1.0.tar.gz (7.9 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.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

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

Hashes for xltemplate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8926b3b4874adfc1856d04c924c867a312bef0e8aea37cf030ca0dae19ca48e8
MD5 99bcd46175cfe57ad143a0e637092d0f
BLAKE2b-256 234c014b0e2c64e92c58ba945fd0ba569629625fbc17eebc5d4c7d3f2925e274

See more details on using hashes here.

Provenance

The following attestation bundles were made for xltemplate-0.1.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.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

Hashes for xltemplate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b0930748c9b56d0df238836b6da8622ee47a91a2ffb8110d038c2c4f6e8a243
MD5 f64c54450937d3aad1267709ad527f74
BLAKE2b-256 cddf036673d2f28a6a976f0ae5f0d3e80f888e892d3dcc3262acc5ee5ab11a04

See more details on using hashes here.

Provenance

The following attestation bundles were made for xltemplate-0.1.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