Composable framework for building styled Excel reports with openpyxl and matplotlib.
Project description
xllayout
Composable framework to build styled Excel reports with openpyxl and matplotlib.
Philosophy
xllayout is split into three layers:
Theme: centralized visual tokens (fonts, fills, borders, number formats, spacing).Components: reusable blocks (TitleBlock,KpiCard,TableBlock,MatplotlibChart, etc.).Layouts: sheet composition using absolute canvas coordinates orGrid12.
This lets you place components at any coordinate without relying on cursor-based writing.
Structure
xllayout/
pyproject.toml
xllayout/
__init__.py
core/
canvas.py
grid.py
theme.py
formats.py
utils.py
components/
title.py
text.py
section.py
kpi.py
table.py
chart.py
layouts/
summary.py
writer/
workbook.py
examples/
build_summary.py
Install
Editable (recommended for development):
pip install -e ".[charts]"
Standard install:
pip install ".[charts]"
- Base dependency:
openpyxl - Optional extra
charts:matplotlib,Pillow
Quick API
from xllayout.core.theme import LightTheme
from xllayout.layouts.summary import ExecutiveSummaryData
from xllayout.writer.workbook import ReportWriter
writer = ReportWriter(theme=LightTheme(), detect_collisions=True)
wb = writer.new_workbook()
writer.build_summary_sheet(wb, data) # data: ExecutiveSummaryData
wb.save("report.xlsx")
Table Cell Styling (v1.1.0)
TableBlock now supports per-column text/cell styling:
from xllayout.components.table import TableBlock
from xllayout.core.cell_style import CellStyleSpec
table = TableBlock(
headers=["id", "descripcion", "valor"],
rows=[[1, "Texto largo que debe envolver en varias lineas", 1200]],
col_widths=[10, 34, 14],
number_formats_by_col={3: "#,##0"},
body_style_by_col={
1: CellStyleSpec(align_horizontal="center", bold=True),
2: CellStyleSpec(wrap_text=True, align_vertical="top"),
3: CellStyleSpec(align_horizontal="right", font_color="#1B4D8A"),
},
header_style=CellStyleSpec(
bold=True,
align_horizontal="center",
fill_color="#E2EAF3",
border_style="thin",
border_color="#D0D7DE",
),
header_row_height=24,
default_row_height=32,
)
Supported style attributes (CellStyleSpec):
- font:
font_name,font_size,bold,italic,underline,font_color - cell:
fill_color,border_style,border_color - alignment:
align_horizontal,align_vertical,wrap_text,shrink_to_fit,text_rotation - format:
number_format
Canvas vs Grid12
Absolute placement:
from xllayout.core.canvas import SheetCanvas
canvas = SheetCanvas(ws, theme, detect_collisions=True)
canvas.put(component, row=5, col=3)
Grid placement:
from xllayout.core.grid import Grid12
grid = Grid12(canvas) # 12 tracks
grid.put(component, y=4, x=1, w=6, h=5)
If detect_collisions=True, overlapping components raise ValueError.
Build a New Layout
- Create a typed input dataclass under
layouts/. - In
build(ws), initializeSheetCanvasand optionallyGrid12. - Place components with
canvas.put(...)orgrid.put(...). - Expose a facade method in
ReportWriter.
Run the example
python examples/build_summary.py
Output:
examples/output/summary_report_example.xlsx
Versioning and publishing
- Uses SemVer (
1.0.0,1.0.1,1.1.0, ...). - Recommended for teams: publish to a private PyPI-compatible registry.
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
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 xllayout-1.1.0.tar.gz.
File metadata
- Download URL: xllayout-1.1.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc98d8edecffe3de32efd74900f1591572dfeeb393075d3f9734b604d5bcbbf9
|
|
| MD5 |
9aea0c7dad3b93124d79579df12c52f5
|
|
| BLAKE2b-256 |
35ebfa013f01504b027af2720845f5391a3a94dfa6685161922de38926447916
|
File details
Details for the file xllayout-1.1.0-py3-none-any.whl.
File metadata
- Download URL: xllayout-1.1.0-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d1244024926b2da0cf4aab83dc457925da213d3d98d7a23c5714ffdc58aa679
|
|
| MD5 |
34404869ce1c586bc0e3c4544529b060
|
|
| BLAKE2b-256 |
b4e54d8a411b6cfd319c3054abe64484d13e0d063e18507d79f033b5a302cdb4
|