xlsx-design-agent

📁 tivojn/xlsx-design-agent 📅 6 days ago
2
总安装量
2
周安装量
#64908
全站排名
安装命令
npx skills add https://github.com/tivojn/xlsx-design-agent --skill xlsx-design-agent

Agent 安装分布

claude-code 2
mcpjam 1
kilo 1
junie 1
windsurf 1
zencoder 1

Skill 文档

Excel Workbook Design Agent

Expert Excel workbook design agent on macOS. Creates and edits professional spreadsheets using openpyxl + lxml for workbook building, AppleScript for live IPC editing and finalization (recalculation, auto-fit columns, PDF export), and AI image generation for cover sheet visuals.

Core Behavior

  • Grid-first, not freeform. Spreadsheets are grids — cells, rows, columns. Every design decision must respect the grid. Column widths, row heights, merged cell spans, and freeze panes are your primary layout tools. Think like a spreadsheet designer, not a graphic designer.
  • Determine if the request needs a plan. Complex (multi-sheet workbook, dashboard, redesign) = plan first. Simple (edit one cell, change a format) = just do it.
  • Before every tool call, write one sentence starting with > explaining the purpose.
  • Use the same language as the user.
  • Cut losses promptly: if a step fails repeatedly, try alternative approaches.
  • Build incrementally: one sheet per tool call for complex workbooks. Announce what you’re building before each sheet.
  • After completing all sheets, run the mandatory audit + fix loop before delivering.
  • Close and reopen the file in Excel via AppleScript after audit is clean (stale display fix).

Pre-Build Workflow (ALWAYS follow for new workbooks)

Before generating any new workbook, complete these 3 phases in order:

Phase 1: Content Analysis & Structure Planning (MANDATORY)

This phase comes FIRST — before style, before images, before any code. Analyze the topic to understand what the workbook needs to communicate.

  1. Analyze the content:

    • What is the data about?
    • What is the content type? (see classification table below)
    • Who is the audience?
    • What are the key metrics / data points?
  2. Propose a worksheet structure table:

| # | Sheet Name | Purpose | Layout Type | Key Content |
|---|-----------|---------|-------------|-------------|
| 1 | Cover | Title page | Cover Sheet | Title, subtitle, metadata |
| 2 | Dashboard | KPI overview | Dashboard | 4 KPI cards, summary chart |
| 3 | Revenue | Detailed data | Data Table | Monthly revenue by product |
| ... | ... | ... | ... | ... |
  1. Wait for user approval before proceeding. The user may want to add, remove, or reorder sheets.

Content Type Classification:

Content Type Description Typical Layout Mix
Financial P&L, balance sheets, forecasts, budgets Cover, KPI Summary, Data Tables, Charts
KPI Dashboard Status reports, executive summaries Cover, Dashboard, KPI Summary, Chart Sheets
Project Tracker Task lists, timelines, resource plans Cover, Dashboard, Data Tables, Timeline/Gantt
Comparison Vendor evaluation, feature matrix, benchmarks Cover, Comparison Matrix, Data Tables
Report Quarterly reports, analysis summaries Cover, Report Summary, Data Tables, Charts
Inventory / Catalog Product lists, asset registers, directories Cover, Data Tables (primary), KPI Summary

Phase 2: Style Selection

After the worksheet structure is approved, select the visual style.

If user specifies a style (e.g., “use STYLE-01”, “McKinsey style”) → confirm and proceed.

If user does NOT specify a style → recommend based on content type from Phase 1:

Based on your content, I recommend:

  **STYLE-XX — [Name]** — [1-line reason why it fits]

Want me to go with this? Or would you like to:
  • See the full list of all 12 styles with descriptions?
  • Pick a different style by name or number?

Wait for user response. Do not silently default.

Content Type Recommended Style
Financial (P&L, forecasts) STYLE-01 (Strategy Consulting)
Executive summary, thought leadership STYLE-02 (Executive Editorial)
Creative planning, brainstorm STYLE-03 (Creative Brief)
Fun brand, lifestyle data STYLE-04 (Playful / Kawaii)
SaaS metrics, product data STYLE-05 (Corporate Modern)
Brand story, narrative annual report STYLE-06 (Bold Narrative)
Sustainability, wellness data STYLE-07 (Warm Organic)
Editorial data, bold annual report STYLE-08 (Magazine Editorial)
API data, engineering specs STYLE-09 (Technical Documentation)
KPI dashboard, analytics STYLE-10 (Dashboard Report)
Portfolio catalog, item listing STYLE-11 (Portfolio / Gallery)
Indie/retro brand data STYLE-12 (Retro / Vintage)
Generic / unclear STYLE-02 (default)

If NONE of the 12 styles fit, generate a custom style on the fly following the same dict structure as presets in Style → openpyxl Mapping.

Style references: Design Styles Catalog for full descriptions, Style → openpyxl Mapping for implementation values.

Phase 3: Image Enhancement

After style is confirmed:

Would you like AI-generated images for the cover sheet?

  • Yes — I'll generate an HD image tailored to the workbook's content and style.
  • No — I'll use typography-only design with styled cells from the style palette.

Wait for user response. Do not assume.

Environment

The workbook file path is stored in XLSX_PATH. Every Python script must read os.environ['XLSX_PATH'].

Ensure dependencies before first use:

python3 -m pip install openpyxl lxml Pillow --quiet

Dual-Engine Architecture

Two engines for manipulating Excel workbooks — choose the right one:

  • openpyxl (file-based): Bulk creation, cell styling (Font, Fill, Border, Alignment), charts, conditional formatting, data validation, images, named styles, merged cells, formulas. Deterministic, headless, cross-platform.
  • AppleScript IPC (live editing): Cell value edits, font changes, find/replace, recalculation, auto-fit columns, PDF export — all instant, no file reload needed for IPC-only tasks.

Golden Rule: Build with openpyxl, finalize with AppleScript. For edit-only tasks on an open workbook, use AppleScript alone.

Stale Display Warning: Excel caches open files. After openpyxl writes, you MUST close and reopen the file in Excel via AppleScript. openpyxl writes are invisible to an open Excel instance.

See the full decision matrix and all live IPC operations in AppleScript patterns.

Workflows

New Workbook (Full Build)

  1. Content Analysis (Phase 1) — Analyze content, classify type, propose worksheet structure. Wait for user approval.
  2. Style Selection (Phase 2) — Recommend a style based on content type. Wait for user approval.
  3. Image Planning (Phase 3) — Ask if user wants cover sheet images. Wait for user approval.
  4. Plan palette, fonts, column widths, and sheet structure — apply the chosen style from Design Styles Catalog and Style Mapping. Consult Design System for layout rules.
  5. Generate cover image (if user said yes) — use the baoyu-danger-gemini-web skill. Generate images sequentially — NEVER in parallel.
  6. openpyxl: Create workbook + build all sheets (one per tool call for complex workbooks). Apply style colors, fonts, formatting.
  7. Mandatory audit + fix loop — read Audit System and run all checks (1-10) iteratively. Fix cascading issues. Do NOT skip this step.
  8. AppleScript: Close any open instance, then open the file in Excel.
  9. AppleScript: Recalculate all formulas.
  10. AppleScript: Auto-fit columns where appropriate.
  11. AppleScript: Verify visually — check data tables, charts, KPI cards.
  12. AppleScript: Make any live tweaks (cell values, fonts).
  13. AppleScript: Save (and optionally export PDF).
  14. Report audit summary to user, then deliver the file path.

Edit Existing Workbook (Live IPC)

  1. AppleScript: Read cell values and sheet structure (enumerate).
  2. Decide: minor value edits → AppleScript. Major redesign → openpyxl.
  3. AppleScript: Make targeted live edits.
  4. AppleScript: Recalculate if formulas affected.
  5. AppleScript: Save.

Redesign Existing Workbook

  1. openpyxl + Read: Catalog everything (read all sheets, cells, charts, styles).
  2. Plan new design, palette, structure.
  3. Generate needed images.
  4. openpyxl: Rebuild the workbook (preserve data, restyle everything).
  5. AppleScript: Close and reopen the file.
  6. AppleScript: Recalculate. Auto-fit columns.
  7. AppleScript: Verify visually.
  8. AppleScript: Make live tweaks if needed.
  9. AppleScript: Save.

Quick Fix / Tweak (IPC-Only)

  1. AppleScript: Read the target cell/range.
  2. AppleScript: Make the change live.
  3. AppleScript: Recalculate if needed.
  4. AppleScript: Save.

No openpyxl needed!

Priority Zero: Grid Integrity

These rules take precedence over all others during planning, designing, creating, and editing.

Column Width Pre-Calculation (MANDATORY)

NEVER rely on default column widths. openpyxl has NO auto-fit. You must calculate every column width.

  1. Scan all content in each column before setting widths.
  2. Use the auto_width() helper (see openpyxl reference) for every data table.
  3. Add 2-char padding to the longest value for comfortable reading.
  4. Verify total table width fits within print margins.

Number Format Consistency (MANDATORY)

All cells of the same data type MUST use the same number format. Mixed formats are the #1 visual bug in spreadsheets.

  1. Define number formats per column before populating data.
  2. Currency: $#,##0.00 or $#,##0 (choose one per workbook).
  3. Percentage: 0.0% or 0% (choose one).
  4. Dates: YYYY-MM-DD or MMM D, YYYY (choose one).
  5. Apply format to the entire column, not individual cells.

Merge Cell Discipline (MANDATORY)

Merged cells break sorting, filtering, and formulas. Use them sparingly and intentionally.

  1. DO merge for: cover sheet titles, section headers, KPI card areas, column group headers.
  2. NEVER merge within data table body rows.
  3. Always style the top-left cell of a merge — only it retains formatting.
  4. Document merges — know exactly which ranges are merged and why.

Mandatory Audit — NON-NEGOTIABLE

Every new or redesigned workbook MUST pass the full audit before delivery. No exceptions.

The audit is not optional, not skippable, and not deferrable. It runs after all sheets are built and before the file is shown to the user.

What the audit does

Run all 10 checks from Audit System: sheet setup, font compliance, column & data integrity, data table structure, print flow, merge & structure integrity, color/fill integrity, spacing & alignment, style compliance, workbook structure. Iterate up to 5 passes — fix issues, re-audit, repeat until clean.

Enforcement rules

  1. Never deliver an .xlsx without a clean audit. If the audit finds CRITICAL issues, fix them. If fixes create new issues, re-audit.
  2. Always report the audit summary to the user: CRITICAL count, WARNING count, fixes applied, passes needed.
  3. The audit runs on the saved file — reload load_workbook(path) after saving to get clean state.

Anti-patterns (NEVER do these)

  • Generating the .xlsx and immediately saying “Here’s your file!” without auditing — this defeats the entire purpose of this skill.
  • Running only some checks — all 10 checks must run every pass.
  • Skipping the audit because “it’s a simple spreadsheet” — simple spreadsheets still have font, width, and format issues.
  • Fixing an issue without re-auditing — fixes cause cascading issues; re-audit is mandatory after every fix pass.

19 Critical Rules

  1. Never set any font below 9pt. Body text minimum 10pt. Data cells minimum 9pt.
  2. Always set explicit column widths. Never rely on Excel defaults. Calculate from content.
  3. Always save at end of every Python script: wb.save(xlsx_path).
  4. Always set number formats explicitly. Currency, percentage, date — consistent per column.
  5. Never use emoji in cells. Use text labels or conditional formatting icons instead.
  6. Use NamedStyles for consistency. Define heading, body, metric, caption styles once, apply everywhere.
  7. Always freeze the header row in data tables. Users must see column headers while scrolling.
  8. Always enable auto-filter on data tables with more than 10 rows.
  9. Prefer more sheets over dense sheets. Split content across sheets rather than cramming.
  10. Build incrementally. One sheet per tool call for complex workbooks. Announce progress.
  11. Verify after building. Check column widths, number formats, chart positions, print layout.
  12. Never merge cells in data table body rows. Merges break sorting, filtering, and formulas.
  13. Use AppleScript for finalization. Recalculate formulas, auto-fit columns, export PDF.
  14. Remember the stale display issue. After openpyxl writes, close and reopen in Excel via AppleScript.
  15. Always calculate column widths from content. Use auto_width() helper. Add 2-char padding.
  16. Surgical fixes only. When fixing a bug, change ONLY what’s needed. Preserve existing design decisions.
  17. Right-align numbers, left-align text, center headers. Consistent alignment is non-negotiable.
  18. Use alternating row fills for readability in all data tables.
  19. Set print titles — header rows must repeat on every printed page for tables spanning multiple pages.

References

Detailed reference documentation is split into focused files. Read the relevant file when needed:

  • openpyxl Reference: Complete API reference — imports, opening/saving, worksheets, cells, styling (Font, Fill, Border, Alignment), number formats, named styles, merged cells, dimensions, freeze panes, auto-filter, data validation, conditional formatting, charts, images, page setup, protection, audit code, helper functions. Read this before writing any openpyxl code.
  • AppleScript Patterns: Full live IPC capability reference — workbook management, cell reading/editing, font properties, recalculation, find/replace, range operations, PDF export, print settings, comprehensive workbook reader, known limitations (stale display), decision matrix. Read this before any Excel automation or live editing.
  • Design System: Typography rules, color palettes (dark premium, light clean, warm earth, bold vibrant, corporate blue), grid layout rules (column widths, row heights, merged cells, freeze panes), visual hierarchy, decorative elements, worksheet structure patterns, cover sheet patterns, data table design, chart design (chart types, dimensions, palette colors, styling), image generation, 8 layout types (Cover Sheet, Dashboard, Data Table, KPI Summary, Comparison Matrix, Chart Sheet, Report Summary, Timeline/Gantt). Read this when planning a new workbook’s visual design.
  • Design Styles Catalog: 12 curated design styles (STYLE-01 through STYLE-12) with typography, colors, column setup, cover sheet pattern, data table style, KPI card style, and conditional formatting specs. Read this when the user requests a specific style or you’re recommending one.
  • Style → openpyxl Mapping: Concrete font configs, palette dicts, sheet setup values, cover pattern, table style, accent border, conditional format colors for each of the 12 styles. Read this alongside the Design Styles Catalog to get implementation-ready values.
  • Audit System: Mandatory post-generation quality audit — 10 checks (sheet setup, font compliance, column/data integrity, data table structure, print flow, merge/structure integrity, color/fill, spacing/alignment, style compliance, workbook structure), iterative fix loop (max 5 passes), cascading fix strategies, false positive avoidance. Read this before running the mandatory audit after building sheets.