Office DOCX
Use this skill for Word .docx tasks. Implement with C# on .NET + OpenXML SDK.
Operating Model
dotnetfrom PATH; NuGet packageDocumentFormat.OpenXml.- Copy
assets/dotnet-starter/as starting point when useful. - Preserve source document; write result to a separate
.docx. - Keep content editable (paragraphs, runs, tables, styles, fields, drawings).
Task Selection
| Task | Read | Focus |
|---|---|---|
| Create new document | references/create-docx.md |
Package, body, styles, page setup, tables, images, fields |
Edit existing .docx |
references/edit-existing-docx.md |
Copy to output, inspect, modify content |
| Apply/imitate template | references/template-formatting.md |
Transfer styles/theme/numbering safely |
| Validate/repair | references/validation.md |
OpenXML validation, package inspection |
| Structural rules | references/openxml-rules.md |
Element ordering, units, sections, tables |
Read the matching reference, implement, run, validate with scripts/check-docx.py.
Key Rules
- Use SDK classes, not raw ZIP string edits.
- Text replacement: single-run matches only; multi-run → paragraph-level rewrite.
- Generated docs: define styles first, then content via style IDs.
- CJK: set East Asian fonts in
RunFonts; confirm spacing and hierarchy. - Final
sectPrmust be last child ofw:body.