$npx -y skills add chacosoldier/compabob --skill document-exportCreate a PDF, Excel (.xlsx), or Word (.docx) file from content. Use for "/document-export", "make a PDF", "export to Excel", "put this in a spreadsheet", "save this as a Word doc", or when the user needs a shareable office document rather than a note or a raw HTML page.
| 1 | # Document Export |
| 2 | |
| 3 | Turn content into a real office file: a **PDF**, an **Excel workbook**, or a |
| 4 | **Word document**. The skill ships three helper scripts that do the file writing |
| 5 | deterministically; your job is to assemble the content and call the right one. |
| 6 | |
| 7 | These scripts use the Python standard library only, so there is nothing to |
| 8 | install for Excel and Word. PDF needs a browser or a PDF tool on the machine |
| 9 | (the script finds it, or tells the user what to install). |
| 10 | |
| 11 | Save every output to `reports/` as `YYYY-MM-DD-<slug>.<ext>`, then tell the user |
| 12 | the path. |
| 13 | |
| 14 | |
| 15 | |
| 16 | PDF is produced by rendering an HTML file. Two cases: |
| 17 | |
| 18 | - **Rich, visual page** (architecture, dashboard, comparison): use the |
| 19 | `visual-explainer` skill to build the HTML, then convert it. |
| 20 | - **Plain document** (a letter, a report, a write-up): wrap the content in this |
| 21 | minimal template and save it as an `.html` file: |
| 22 | |
| 23 | ```html |
| 24 | <!DOCTYPE html> |
| 25 | <html><head><meta charset="utf-8"><title>TITLE</title> |
| 26 | <style> |
| 27 | @page { margin: 2cm; } |
| 28 | body { font: 11pt/1.55 -apple-system, "Segoe UI", Roboto, sans-serif; |
| 29 | color: #1a1a1a; max-width: 46em; margin: 0 auto; } |
| 30 | h1, h2, h3 { line-height: 1.25; } |
| 31 | h1 { font-size: 1.8em; } h2 { font-size: 1.35em; margin-top: 1.6em; } |
| 32 | table { border-collapse: collapse; width: 100%; } |
| 33 | th, td { border: 1px solid #ccc; padding: 6px 10px; text-align: left; } |
| 34 | code { background: #f4f4f4; padding: 1px 4px; border-radius: 3px; } |
| 35 | </style></head><body> |
| 36 | <!-- CONTENT --> |
| 37 | </body></html> |
| 38 | ``` |
| 39 | |
| 40 | Then convert: |
| 41 | |
| 42 | ```bash |
| 43 | python3 .claude/skills/document-export/to_pdf.py <input.html> reports/<YYYY-MM-DD>-<slug>.pdf |
| 44 | ``` |
| 45 | |
| 46 | It tries headless Chrome first, then weasyprint, then wkhtmltopdf. If it reports |
| 47 | that no engine is found, relay its install hint to the user; do not try to work |
| 48 | around it. |
| 49 | |
| 50 | ## Excel (.xlsx) |
| 51 | |
| 52 | Build a JSON spec, write it to a temporary file, and run the writer. |
| 53 | |
| 54 | Spec shape: |
| 55 | |
| 56 | ```json |
| 57 | { |
| 58 | "sheets": [ |
| 59 | { |
| 60 | "name": "Results", |
| 61 | "header": true, |
| 62 | "rows": [["Name", "Score"], ["Alice", 90], ["Bob", 85]], |
| 63 | "widths": [24, 10] |
| 64 | } |
| 65 | ] |
| 66 | } |
| 67 | ``` |
| 68 | |
| 69 | - `header: true` bolds the first row. `widths` (column widths in characters) is |
| 70 | optional. Multiple sheets are allowed. |
| 71 | - Cell values may be strings, numbers, booleans, or `null` (an empty cell). |
| 72 | Keep numbers as numbers in the JSON so Excel treats them as numeric. |
| 73 | |
| 74 | Run it: |
| 75 | |
| 76 | ```bash |
| 77 | python3 .claude/skills/document-export/to_xlsx.py /tmp/export-spec.json reports/<YYYY-MM-DD>-<slug>.xlsx |
| 78 | ``` |
| 79 | |
| 80 | You can also pipe the spec on stdin by passing `-` instead of a file path. |
| 81 | |
| 82 | ## Word (.docx) |
| 83 | |
| 84 | Build a JSON spec of blocks, then run the writer. |
| 85 | |
| 86 | Spec shape: |
| 87 | |
| 88 | ```json |
| 89 | { |
| 90 | "title": "Optional document title", |
| 91 | "blocks": [ |
| 92 | {"type": "heading", "level": 2, "text": "A section"}, |
| 93 | {"type": "paragraph", "text": "A plain paragraph."}, |
| 94 | {"type": "paragraph", "runs": [ |
| 95 | {"text": "mixed ", "bold": true}, |
| 96 | {"text": "formatting", "italic": true} |
| 97 | ]}, |
| 98 | {"type": "bullets", "items": ["first point", "second point"]}, |
| 99 | {"type": "numbered", "items": ["step one", "step two"]}, |
| 100 | {"type": "table", "header": true, "rows": [["Col A", "Col B"], ["1", "2"]]} |
| 101 | ] |
| 102 | } |
| 103 | ``` |
| 104 | |
| 105 | - `heading` levels are 1 to 3. A `paragraph` carries plain `text` (with optional |
| 106 | `bold` / `italic` for the whole paragraph) or a list of `runs` for mixed |
| 107 | formatting. `table` rows are lists of cell strings; `header: true` bolds the |
| 108 | first row. |
| 109 | |
| 110 | Run it: |
| 111 | |
| 112 | ```bash |
| 113 | python3 .claude/skills/document-export/to_docx.py /tmp/export-spec.json reports/<YYYY-MM-DD>-<slug>.docx |
| 114 | ``` |
| 115 | |
| 116 | ## After exporting |
| 117 | |
| 118 | - Delete any temporary spec file you created. |
| 119 | - Give the user the exact path of the file. |
| 120 | - If the user wants to share the file, that is an outward action: hand it over, |
| 121 | do not send it anywhere yourself. |
| 122 | |
| 123 | ## Scope |
| 124 | |
| 125 | These writers cover the structure that carries content: values, headings, |
| 126 | formatting, lists, simple tables, column widths. They do not do Excel formulas, |
| 127 | charts, or merged cells, or Word images, footnotes, or page headers. If a |
| 128 | request needs those, say so and either extend the script or, if the user has the |
| 129 | `openpyxl` or `python-docx` library available, write a one-off script with it |
| 130 | instead. |