|
| 1 | +Using xpyxl with xlsxwriter (external agents) |
| 2 | +- Install: dependency declared as `xlsxwriter>=3.1.0`. Import `import xpyxl as x`. |
| 3 | +- Build: compose nodes (no coordinates) then save with the engine you want: `x.workbook()[x.sheet("Demo")[...]].save("out.xlsx", engine="xlsxwriter")`. |
| 4 | +- Primitives: `x.cell[...]`, `x.row[...]`, `x.col[...]`, `x.table()[...]`, `x.vstack(..., gap=0, style=[...])`, `x.hstack(..., gap=0, style=[...])`, `x.space(rows=1, height=None)`, `x.sheet(name, background_color=None)`, `x.workbook()[...]`. |
| 5 | +- Table inputs: sequence of sequences, sequence of dicts (header from keys), or dict-of-lists (columns zipped). `header_style=[...]`, `style=[...]`, `column_order=[...]`. |
| 6 | +- Saving: engine is chosen only at save time; both engines yield equivalent output. Use `engine="xlsxwriter"` when you want speed/low memory (as in README benchmarks). |
| 7 | +- Backgrounds: `sheet(..., background_color="#F8FAFC")` paints the grid (render fills a large area since xlsxwriter lacks sheet fill). |
| 8 | + |
| 9 | +Precomputed styles (combine in `style=[...]`) |
| 10 | +- Typography: `text_xs, text_sm, text_base, text_lg, text_xl, text_2xl, text_3xl, bold, italic, mono`. |
| 11 | +- Text colors: `text_red, text_green, text_blue, text_orange, text_purple, text_black, text_gray, text_muted, text_primary, text_white`. |
| 12 | +- Backgrounds: `bg_red, bg_primary, bg_muted, bg_success, bg_warning, bg_info`. |
| 13 | +- Alignment & layout: `text_left, text_center, text_right, align_top, align_middle, align_bottom, wrap, nowrap, wrap_shrink, allow_overflow, row_height(n), row_width(n)`. |
| 14 | +- Borders: `border_all, border_top, border_bottom, border_left, border_right, border_x, border_y, border_thin, border_medium, border_thick, border_dashed, border_dotted, border_double, border_none` plus color helpers `border_red/green/blue/orange/purple/black/gray/white/muted/primary`. |
| 15 | +- Tables: `table_bordered`, `table_banded`, `table_compact`. |
| 16 | +- Number/date formats: `number_comma`, `number_precision`, `percent`, `currency_usd`, `currency_eur`, `date_short`, `datetime_short`, `time_short`. |
| 17 | + |
| 18 | +Common patterns |
| 19 | +- Simple sheet: `x.sheet("Summary")[x.row(style=[x.text_2xl, x.bold])["Title"], x.row()["A", 1]]`. |
| 20 | +- Styled table: `x.table(header_style=[x.text_sm, x.text_gray], style=[x.table_bordered, x.table_compact])[{"Region": "EMEA", "Units": 1200}, ...]`. |
| 21 | +- Layouts: `x.vstack(...)` for vertical stacking with optional `gap`; `x.hstack(...)` to place blocks side by side; sprinkle `x.space()` for padding. |
| 22 | +- Multi-sheet: collect `SheetNode`s (each from `x.sheet(...)[...]`) into `x.workbook()[sheet1, sheet2]`. |
| 23 | + |
| 24 | +Real-world examples (ready to reuse) |
| 25 | +- Sales dashboard: |
| 26 | + `x.workbook()[x.sheet("Sales", background_color="#F8FAFC")[x.row(style=[x.text_2xl, x.bold, x.text_blue])["Q3 Overview"], x.space(), x.table(header_style=[x.text_sm, x.text_gray], style=[x.table_bordered, x.table_banded, x.table_compact])[{"Region": "EMEA", "Units": 1200, "Price": 19.0}, {"Region": "APAC", "Units": 900, "Price": 21.0}, {"Region": "AMER", "Units": 1500, "Price": 18.5}], x.space(), x.hstack(x.row(style=[x.text_sm, x.text_gray])["Generated with xpyxl"], x.cell(style=[x.text_sm, x.text_gray])["Engine: xlsxwriter"], gap=2)]]`. Save with `engine="xlsxwriter"`. |
| 27 | +- Two-column layout: |
| 28 | + `x.workbook()[x.sheet("Metrics")[x.hstack(x.vstack(x.row(style=[x.text_lg, x.bold])["KPI"], x.row()["MRR", 125000], x.row()["Churn", "2.1%"], gap=1, style=[x.border_all, x.bg_muted]), x.vstack(x.row(style=[x.text_lg, x.bold])["Notes"], x.row(style=[x.wrap])["Performance improved; keep monitoring churn drivers across regions."], gap=1, style=[x.border_all, x.bg_info]), gap=2)]]`. Save with `engine="xlsxwriter"`. |
| 29 | +- Minimal CSV-like export: |
| 30 | + `x.workbook()[x.sheet("Data")[x.table(style=[x.table_compact])[{"id": 1, "name": "alpha"}, {"id": 2, "name": "beta"}]]]`. Save with `engine="xlsxwriter"` for faster large writes. |
0 commit comments