{"success":true,"name":"microsoft-office","description":"Create, read, and edit Word, PowerPoint, and Excel files.","category":"productivity","path":"productivity/microsoft-office/SKILL.md","file":"SKILL.md","content":"---\nname: microsoft-office\ndescription: Create, read, and edit Word, PowerPoint, and Excel files.\nversion: 2.0.0\nauthor: Nous Research\nlicense: MIT\nplatforms: [linux, macos, windows]\nmetadata:\n  hermes:\n    tags: [office, word, docx, powerpoint, pptx, excel, xlsx, csv, documents, slides, spreadsheets]\n    category: productivity\n    related_skills: [pdf]\n---\n\n# Microsoft Office Skill\n\nCreate, read, edit, and template Word (`.docx`), PowerPoint (`.pptx`), and\nExcel (`.xlsx`, `.csv`) files offline with small Python CLIs built on\npython-docx, python-pptx, and openpyxl. Office itself is never needed. It does\nnot open legacy binary formats (`.doc`, `.ppt`, `.xls`) and does not render\npages without LibreOffice.\n\n## When to Use\n\nPick the format, then read its reference with `skill_view` before working:\n\n| File | Reference | Typical asks |\n| --- | --- | --- |\n| `.docx` | `references/word.md` | reports, letters, contracts, `{{token}}` templates, tracked changes, comments |\n| `.pptx` | `references/powerpoint.md` | pitch decks, brand-template decks, chart refreshes, speaker notes, slide PNGs |\n| `.xlsx`, `.csv` | `references/excel.md` | styled multi-sheet workbooks, formulas, charts, CSV conversion, row/column restructures |\n\nDeeper notes: `references/revisions-and-comments.md` (Word review markup) and\n`references/restructuring.md` (Excel reference shifting).\n\n- Not for `.doc`/`.ppt`/`.xls`: convert first with\n  `soffice --headless --convert-to docx|pptx|xlsx old-file` when LibreOffice is installed.\n- Not for `.odt`/`.odp`/`.ods`, or WYSIWYG layout work.\n\n## Prerequisites\n\n- Python 3.10+ with `python-docx`, `python-pptx`, and `openpyxl` (import names\n  `docx`, `pptx`, `openpyxl`).\n- Pick the interpreter with `terminal`. Use `python` when it already imports\n  the libraries (the Hermes Docker image ships them). Otherwise, when `hermes`\n  is on PATH, let Hermes build its shared, pinned documents environment under\n  the Hermes home: it survives container restarts, never touches the Hermes\n  install itself, and is safe to run from several agents at once. When it is\n  not (the terminal runs in a Docker sandbox, which has no Hermes), the block\n  builds a venv in the sandbox home with the same pinned versions. Use this\n  exact block in every document skill so they all share one environment:\n\n  ```bash\n  python -c \"import docx, pptx, openpyxl\" 2>/dev/null && PY=python || if command -v hermes >/dev/null 2>&1; then\n    PY=\"$(hermes pm environment documents --extra documents --extra documents-pdf)\"\n  else\n    PY=\"$HOME/.cache/hermes-docs-venv/bin/python\"\n    \"$PY\" -c \"import docx, openpyxl, pptx, reportlab, pypdf, pdfplumber, pypdfium2\" 2>/dev/null || (\n      # Safe to run from several agents at once: each caller builds a private venv,\n      # a symlink publishes the first finished one atomically, the others delete theirs;\n      # a published build is replaced and deleted only while it still fails to import.\n      mkdir -p \"$HOME/.cache\" && cd \"$HOME/.cache\" && stage=\"$(mktemp -d hermes-docs-venv.XXXXXX)\" || exit 1\n      old=\"$(readlink hermes-docs-venv)\"  # the published build, if any (another agent may have just published it)\n      python3 -m venv \"$stage\" &&\n        \"$stage/bin/python\" -m pip install -q --disable-pip-version-check python-docx==1.2.0 openpyxl==3.1.5 python-pptx==1.0.2 reportlab==5.1.0 pypdf==6.21.4 pdfplumber==0.11.10 pypdfium2==5.14.0 &&\n        \"$stage/bin/python\" -c \"import docx, openpyxl, pptx, reportlab, pypdf, pdfplumber, pypdfium2\" &&\n        if [ -z \"$old\" ]; then python3 -c 'import os, sys; os.symlink(*sys.argv[1:])' \"$stage\" hermes-docs-venv\n        elif [ \"$(readlink hermes-docs-venv)\" = \"$old\" ] && ! \"$old/bin/python\" -c \"import docx, openpyxl, pptx, reportlab, pypdf, pdfplumber, pypdfium2\" 2>/dev/null; then\n          ln -s \"$stage\" \"$stage.lnk\" && python3 -c 'import os, sys; os.replace(*sys.argv[1:])' \"$stage.lnk\" hermes-docs-venv &&\n            case \"$old\" in hermes-docs-venv.??????) rm -rf \"$old\" ;; esac\n        fi 2>/dev/null\n      [ \"$(readlink hermes-docs-venv)\" = \"$stage\" ] || rm -rf \"$stage\" \"$stage.lnk\"\n    )\n  fi\n  export PY\n  \"$PY\" scripts/docx_create.py --help\n  ```\n\n  Run every helper with `\"$PY\"`. In PowerShell (Hermes runs on that host, so\n  it is on PATH):\n  `$env:PY = hermes pm environment documents --extra documents --extra documents-pdf`.\n  Never `pip install` into the interpreter that runs Hermes or into the\n  `hermes pm environment` one; Hermes owns both.\n- Optional: LibreOffice (`soffice`) for PDF export, Excel recalculation, and\n  slide rendering, plus poppler (`pdftoppm` or `pdftocairo`) for slide PNGs.\n  The helpers that need them report what is missing and exit 0.\n\n## How to Run\n\nEvery helper lives in `scripts/`, is an argparse CLI with `--help`, prints\nJSON to stdout, and exits non-zero on failure. Run them with `terminal` from\nthe skill directory. Author JSON specs with `write_file`; read results with\n`read_file` or straight from stdout.\n\n```bash\n\"$PY\" scripts/docx_create.py spec.json out.docx\n\"$PY\" scripts/pptx_create.py deck.json out.pptx\n\"$PY\" scripts/xlsx_create.py spec.json report.xlsx\n```\n\n## Quick Reference\n\n| Task | Word | PowerPoint | Excel |\n| --- | --- | --- | --- |\n| Create from JSON spec | `docx_create.py` | `pptx_create.py` | `xlsx_create.py`, `csv_to_xlsx.py` |\n| Read back | `docx_read.py --text/--structure` | `pptx_read.py --outline` | `xlsx_read.py --sheets/--json` |\n| Edit | `docx_edit.py` | `pptx_edit.py` | `xlsx_edit.py`, `xlsx_restructure.py` |\n| Fill a template | `docx_template.py` | `pptx_from_template.py` | — |\n| Review / check | `docx_revisions.py`, `docx_comments.py`, `docx_validate.py` | `pptx_render.py` (slide PNGs) | `xlsx_recalc.py`, `xlsx_to_csv.py` |\n\nThe per-format reference has the full flag table.\n\n## Procedure\n\n1. Identify the format from the file extension or the ask, and load its\n   reference (`skill_view` with `file_path=references/<format>.md`).\n2. Set `PY` with the Prerequisites block once per session.\n3. Create, edit, or read with that format's helpers; pass an output path to\n   keep the original whenever the helper supports one.\n4. Verify the result as the reference's Verification section says, then give\n   the user the exact output path.\n\n## Converting to PDF\n\nWhen LibreOffice is installed, convert headlessly:\n\n```bash\nsoffice --headless --convert-to pdf --outdir out/ file.docx   # also .pptx, .xlsx\nsoffice --headless --convert-to csv --outdir out/ report.xlsx # first sheet only\n```\n\nCheck first with `command -v soffice || command -v libreoffice`. Fonts not on\nthe host are substituted, so render-check decks before shipping. There is no\npure-Python path to PDF for any of these formats: if `soffice` is missing, say\nso rather than approximating. For other sheets use\n`xlsx_to_csv.py --sheet NAME`.\n\n## Pitfalls\n\n- **Never unzip-and-edit the XML.** These files are zip packages; raw text\n  substitution corrupts them. Edit through the helpers (or the libraries) and\n  use `patch`/`write_file` only for JSON inputs.\n- **Text is split into runs.** Word and PowerPoint fragment text at edit\n  boundaries; the replace helpers merge equal-format runs first, but a match\n  across differently formatted runs takes the first run's formatting.\n- **Nothing computes fields or formulas.** Word TOC/page fields and Excel\n  formulas are filled in by the office app on open (or by `xlsx_recalc.py`).\n- **Encoding.** Write specs as UTF-8; the helpers read UTF-8 explicitly.\n- Format-specific traps are in each reference.\n\n## Verification\n\n- Re-read every output with the format's read helper and check the expected\n  content is there and the old content is gone.\n- Word: `docx_validate.py out.docx` exits 0 after revision, comment, or field\n  surgery.\n- PowerPoint: render with `pptx_render.py` and check each PNG with\n  `vision_analyze` when the render tools exist.\n- Excel: `xlsx_read.py --formulas` lists written formulas; run\n  `xlsx_recalc.py` when cached values matter.\n- The bundled tests are the full contract:\n  `\"$PY\" -m pytest tests/ -q` (needs pytest in that interpreter).\n","linked_files":["LICENSE","references/excel.md","references/powerpoint.md","references/restructuring.md","references/revisions-and-comments.md","references/word.md","scripts/csv_to_xlsx.py","scripts/docx_comments.py","scripts/docx_common.py","scripts/docx_create.py","scripts/docx_edit.py","scripts/docx_read.py","scripts/docx_revisions.py","scripts/docx_template.py","scripts/docx_validate.py","scripts/pptx_create.py","scripts/pptx_edit.py","scripts/pptx_from_template.py","scripts/pptx_read.py","scripts/pptx_render.py","scripts/xlsx_create.py","scripts/xlsx_edit.py","scripts/xlsx_read.py","scripts/xlsx_recalc.py","scripts/xlsx_restructure.py","scripts/xlsx_to_csv.py","tests/test_docx_skill.py","tests/test_powerpoint_skill.py","tests/test_xlsx_skill.py"],"origin":"brimind","owner_id":null,"source":"router"}