|
| 1 | +"""Showcase workbook for the border utility classes.""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import xpyxl as x |
| 6 | + |
| 7 | + |
| 8 | +def cell_border_section() -> x.Node: |
| 9 | + title = x.row(style=[x.text_lg, x.bold])["Cell utilities", "", ""] |
| 10 | + header = x.row(style=[x.text_sm, x.text_gray])["Utility", "Preview", "Notes"] |
| 11 | + |
| 12 | + variants = [ |
| 13 | + ("x.border_all", [x.border_all, x.border_primary], "All sides + brand color"), |
| 14 | + ("x.border_top", [x.border_top, x.border_thick], "Top rule"), |
| 15 | + ("x.border_x", [x.border_x, x.border_green], "Left + right"), |
| 16 | + ("x.border_y", [x.border_y, x.border_dashed], "Top + bottom dashed"), |
| 17 | + ("x.border_bottom", [x.border_bottom, x.border_orange], "Underline style"), |
| 18 | + ] |
| 19 | + |
| 20 | + rows: list[x.Node] = [] |
| 21 | + for label, styles, note in variants: |
| 22 | + preview = x.cell(style=[*styles, x.text_center, x.text_sm])["Sample"] |
| 23 | + rows.append(x.row()[label, preview, note]) |
| 24 | + |
| 25 | + return x.vstack(title, header, *rows) |
| 26 | + |
| 27 | + |
| 28 | +def row_border_section() -> x.Node: |
| 29 | + title = x.row(style=[x.text_lg, x.bold])["Row-level borders", "", ""] |
| 30 | + header = x.row(style=[x.text_sm, x.text_gray])["Utility", "Preview", "Notes"] |
| 31 | + |
| 32 | + variants = [ |
| 33 | + ("x.border_y + x.border_muted", [x.border_y, x.border_muted], "Soft banded rows"), |
| 34 | + ( |
| 35 | + "x.border_top + x.border_bottom + x.border_thick", |
| 36 | + [x.border_top, x.border_bottom, x.border_thick], |
| 37 | + "Strong divider", |
| 38 | + ), |
| 39 | + ("x.border_y + x.border_dotted", [x.border_y, x.border_dotted], "Subtle dotted grid"), |
| 40 | + ] |
| 41 | + |
| 42 | + rows: list[x.Node] = [] |
| 43 | + for label, styles, note in variants: |
| 44 | + rows.append(x.row(style=styles)[label, "Row preview", note]) |
| 45 | + |
| 46 | + return x.vstack(title, header, *rows) |
| 47 | + |
| 48 | + |
| 49 | +def column_border_section() -> x.Node: |
| 50 | + header = x.row(style=[x.text_lg, x.bold])["Column-level borders"] |
| 51 | + details = x.row(style=[x.text_sm, x.text_gray])["Style the column container once and every cell inherits."] |
| 52 | + |
| 53 | + columns = x.hstack( |
| 54 | + x.col(style=[x.border_x, x.border_blue])[ |
| 55 | + x.cell(style=[x.bold])["x.border_x"], |
| 56 | + "keeps", "left & right", "outlined", |
| 57 | + ], |
| 58 | + x.col(style=[x.border_y, x.border_red])[ |
| 59 | + x.cell(style=[x.bold])["x.border_y"], |
| 60 | + "adds", "top & bottom", "per cell", |
| 61 | + ], |
| 62 | + x.col(style=[x.border_all, x.border_muted, x.border_thin])[ |
| 63 | + x.cell(style=[x.bold])["x.border_all"], |
| 64 | + "acts like", "inline cards", "for stacks", |
| 65 | + ], |
| 66 | + gap=2, |
| 67 | + ) |
| 68 | + |
| 69 | + return x.vstack(header, details, columns) |
| 70 | + |
| 71 | + |
| 72 | +def build_workbook() -> x.Workbook: |
| 73 | + border_sheet = x.sheet("Borders")[ |
| 74 | + x.row(style=[x.text_2xl, x.bold])["Border Styles Demo"], |
| 75 | + x.row(style=[x.text_sm, x.text_gray])["Cell, row, and column outlines using utility classes."], |
| 76 | + x.space(), |
| 77 | + cell_border_section(), |
| 78 | + x.space(), |
| 79 | + row_border_section(), |
| 80 | + x.space(), |
| 81 | + column_border_section(), |
| 82 | + x.space(), |
| 83 | + x.row(style=[x.text_sm, x.text_gray])["Generated with xpyxl"], |
| 84 | + ] |
| 85 | + return x.workbook()[border_sheet] |
| 86 | + |
| 87 | + |
| 88 | +def main() -> None: |
| 89 | + workbook = build_workbook() |
| 90 | + output_path = Path("border-styles-demo-output.xlsx") |
| 91 | + workbook.save(output_path) |
| 92 | + print(f"Saved {output_path.resolve()}") |
| 93 | + |
| 94 | + |
| 95 | +if __name__ == "__main__": |
| 96 | + main() |
0 commit comments