Skip to main content

Inject pandas DataFrames into Excel templates with table resizing and pivot refresh.

Project description

pivoteer

CI PyPI License: MIT

pivoteer injects pandas DataFrames into existing Excel templates by editing the underlying XML. It resizes Excel Tables (ListObjects) and forces PivotTables to refresh on open without corrupting pivot caches.

Why pivoteer

Most Python Excel libraries rewrite workbooks, which can break PivotTables, filters, and formatting in real-world templates. pivoteer is designed for enterprise reporting workflows where templates are authored in Excel and must remain intact. It surgically updates only the table data and table metadata so PivotTables remain connected and refresh correctly.

Installation

pip install pivoteer

Quick Start

from pathlib import Path
import pandas as pd

from pivoteer.core import Pivoteer

pivoteer = Pivoteer(Path("template.xlsx"))

df = pd.DataFrame(
    {
        "Category": ["Hardware", "Software"],
        "Region": ["North", "South"],
        "Amount": [120.0, 250.0],
        "Date": ["2024-01-01", "2024-01-02"],
    }
)

pivoteer.apply_dataframe("DataSource", df)
pivoteer.save("report_output.xlsx")

Architecture Overview

  • Input/output: .xlsx files are ZIP archives containing OpenXML parts.
  • Data injection: updates xl/worksheets/sheetN.xml row data using inline strings to avoid touching sharedStrings.xml.
  • Table resizing: updates xl/tables/tableN.xml by recalculating the ref range based on the DataFrame shape.
  • Pivot refresh: sets refreshOnLoad="1" in xl/pivotCache/pivotCacheDefinitionN.xml when present.

Features

  • Surgical Data Injection: updates worksheet XML without touching sharedStrings.
  • Table Resizing: recalculates ListObject ranges to match injected data.
  • Pivot Preservation: sets pivot caches to refresh on load when present.
  • Minimal IO: stream-based ZIP copy-and-replace for stability.

Usage Patterns

Multiple table updates

from pivoteer.core import Pivoteer
import pandas as pd

p = Pivoteer("template.xlsx")
p.apply_dataframe("SalesData", pd.read_csv("sales.csv"))
p.apply_dataframe("CostData", pd.read_csv("costs.csv"))
p.save("report_output.xlsx")

Large datasets

pivoteer is optimized for replacing table data without rewriting the entire workbook. It is a good fit for large tables where preserving PivotTables and filters matters more than Excel formatting for each row.

Limitations

  • The generated test template uses inline strings and does not create pivot caches when the installed xlsxwriter lacks pivot table support.
  • Date formatting is injected as inline text; apply Excel formatting if needed.
  • Shared strings are not modified in Phase 1.
  • PivotTables are refreshed on open via refreshOnLoad, but pivoteer does not recalculate pivot caches or modify pivot layout.

Compatibility

  • Python: 3.10+
  • Excel: Desktop Excel (Windows/macOS) supports refreshOnLoad for PivotTables.
  • Templates: Must include Excel Tables (ListObjects) with stable names.

Troubleshooting

  • "Table not found": Ensure the Excel Table name matches exactly.
  • "Pivot cache not found": The template may not include a PivotTable; this is expected for synthetic templates.
  • "DataFrame is empty": pivoteer refuses empty payloads to protect templates.

Support and Requests

  • Bugs: open a GitHub issue using the Bug Report template.
  • Feature requests: open a GitHub issue using the Feature Request template.
  • Security: follow the reporting process in SECURITY.md.

Security

If you discover a vulnerability, please read SECURITY.md for reporting instructions.

Development

python -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
pytest

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

pivoteer-0.1.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

pivoteer-0.1.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pivoteer-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for pivoteer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1481a5b5a957962e5baf95f9c2f4fde39d4c09ea933949d11a5e8980b3ea9148
MD5 bfcca93710b6e1082677ff79de0c40f1
BLAKE2b-256 4af4b313fe43fd46b3dc6cfccb59eb554f21e28144cbb2c7a36b9d8eba6fb957

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoteer-0.1.1.tar.gz:

Publisher: release.yml on flitzrrr/pivoteer

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

File details

Details for the file pivoteer-0.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pivoteer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd0aaee4a5cf6f5c58e8fa5850049e920e39cf9af5001effc86b55bca4ec08e1
MD5 913060acbc9fb8a2ed2afbfd1d2bbfcb
BLAKE2b-256 ccf67b7b8784cce2c28db0d9922ba8f688063b1f67a3723d67cf1c6047971c54

See more details on using hashes here.

Provenance

The following attestation bundles were made for pivoteer-0.1.1-py3-none-any.whl:

Publisher: release.yml on flitzrrr/pivoteer

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