AGENT SKILL

docx-pro

Word document automation — generating, templating, and parsing .docx files — use when working with Word documents programmatically.

License 许可
MIT
所属仓库
TanNhatCMS/jarvis
最近更新
2026-11-07
Stars
★ 0
Forks
1

01 前言 Front Matter

name
docx-pro
category
document-processing
description
Word document automation — generating, templating, and parsing .docx files — use when working with Word documents programmatically.

03 SKILL.md 正文

Overview

.docx is a zipped XML format (Office Open XML), which makes Word documents surprisingly automatable: generate reports from templates, mail-merge at scale, extract structured content, or convert to other formats. This skill covers template-driven generation and reliable parsing across the major libraries.

When to use

  • Generating contracts, letters, or reports from templates with placeholders
  • Mail-merge style bulk document production
  • Extracting text, tables, headings, or images from .docx files
  • Converting .docx to PDF, HTML, or Markdown
  • Manipulating styles, headers/footers, and tracked changes

Core concepts

Template + data is the winning pattern. Author the document in Word with placeholder syntax ({{name}}, {% for item in items %}), then render with data. This keeps design in the hands of whoever owns the document and logic in code — far more maintainable than building documents paragraph-by-paragraph in code.

docx is XML in a zip. Every library ultimately manipulates word/document.xml inside the archive. Knowing this helps when libraries fall short: you can unzip, inspect, and patch XML directly for edge cases (custom XML parts, content controls, unusual formatting).

Styles beat direct formatting. Documents built on named styles (Heading 1, Normal, custom styles) are parseable and convertible; documents with manual bold/size/color everywhere are fragile. When generating, apply styles; when parsing, key off styles (headings → document outline) rather than font sizes.

Tracked changes and comments live in the XML. Accept/reject revisions programmatically before extraction if you want the "final" text; comments are separate ranges that naive text extractors may interleave or drop.

Fidelity vs structure trade-off. Converting docx → PDF preserves visual fidelity (use a real renderer like LibreOffice headless for best results); docx → Markdown/HTML preserves structure but loses precise layout. Choose by what the consumer needs.

Practical workflow

  1. For generation: create the template in Word with placeholders and real styles; keep logic (loops, conditionals) minimal and readable in the template.
  2. Render with data, then open the output in Word/LibreOffice to verify — automated checks catch missing placeholders, but only eyes catch broken layout (orphaned headings, tables splitting badly).
  3. Handle the edge cases in data: empty lists (hide the table, don't render an empty one), long text (test wrapping), special characters (escape template syntax), missing values (defaults, not blanks).
  4. For parsing: extract by structure — styles for headings, table objects for tables, paragraph iteration for body text; preserve the mapping back to source locations for debugging.
  5. For conversion: prefer headless LibreOffice for docx → PDF fidelity; prefer structure-aware extractors for docx → Markdown/HTML.
  6. Version your templates alongside code — a template change is a code change; test generation in CI with fixture data.

Common pitfalls

  • Placeholders broken across XML runs — Word splits {{name}} into multiple runs if edited mid-word; templates authored carelessly fail to render. Type placeholders in one go, or use content controls.
  • Building documents purely in code for complex layouts — unmaintainable; templates exist for a reason.
  • Ignoring section properties (page size, margins, headers/footers differ per section) when manipulating documents — edits can silently apply to the wrong section.
  • Assuming .doc == .docx — the old binary format needs different tooling; convert legacy .doc files first (LibreOffice headless batch conversion).
  • Losing images on round-trips — images are separate parts referenced by relationship IDs; naive XML patching can orphan them. Use library APIs for image handling.
  • Not testing with tracked changes present — real-world documents arrive with revisions; decide your accept/reject policy up front.

04 同仓库更多 Skills

TanNhatCMS
TanNhatCMS/jarvis

web-scrape

Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.

★ 0
TanNhatCMS
TanNhatCMS/jarvis

design-taste-frontend

tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.

★ 0
TanNhatCMS
TanNhatCMS/jarvis

test-driven-development

Use when implementing any feature or bugfix, before writing implementation code

★ 0
TanNhatCMS
TanNhatCMS/jarvis

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

★ 0
TanNhatCMS
TanNhatCMS/jarvis

requesting-code-review

Use when completing tasks, implementing major features, or before merging to verify work meets requirements

★ 0
TanNhatCMS
TanNhatCMS/jarvis

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

★ 0