Process Microsoft Word documents (.doc and .docx files) by reading content, creating new documents, editing existing ones, and converting between formats (Word, PDF, Markdown, HTML). Use this skill when users mention Word documents, provide .doc/.docx file paths, or request operations like "read this Word file", "create a Word document", "edit this .docx", or "convert Word to PDF/Markdown".
Process Microsoft Word documents with full support for reading, creating, editing, and format conversion. Handle both legacy .doc and modern .docx formats seamlessly.
To determine which operation to perform:
Extract text, tables, and metadata from Word documents.
python3 scripts/read_word.py <file_path> [--format json|markdown|text]
When user asks "Read this Word file" or provides a .doc/.docx path:
python3 scripts/read_word.py ~/Documents/report.docx --format markdown
pip install python-docx)brew install antiword or pip install textract)Generate new Word documents from structured content.
python3 scripts/create_word.py <output_path> <content_json>
Provide content as JSON with these optional fields:
{
"title": "Document Title",
"subtitle": "Optional subtitle",
"metadata": {
"author": "Author Name",
"subject": "Document Subject"
},
"paragraphs": [
"Simple paragraph text",
{
"text": "Styled paragraph",
"style": "Heading 1",
"bold": true,
"alignment": "center"
}
],
"tables": [
[
["Header 1", "Header 2"],
["Row 1 Col 1", "Row 1 Col 2"]
]
],
"lists": [
{
"ordered": false,
"items": ["Item 1", "Item 2", "Item 3"]
}
]
}
When user requests "Create a Word document with a title, introduction, and conclusion":
python3 scripts/create_word.py ~/Documents/output.docx '{"title":"My Report","paragraphs":["Introduction text","Conclusion text"]}'
Text Formatting (applies to runs):
bold: true/false - Bold textitalic: true/false - Italic textunderline: true/false - Underlined textfont_size: number - Font size in points (e.g., 12, 14, 16)font_name: string - Font family (e.g., "Arial", "Times New Roman", "Calibri")font_color: string or array - Text color as hex "#FF0000" or RGB array [255, 0, 0]Paragraph Formatting:
alignment: "left" | "center" | "right" | "justify"line_spacing: number - Line spacing (1.0 = single, 1.5, 2.0 = double, etc.)space_before: number - Space before paragraph in pointsspace_after: number - Space after paragraph in pointsleft_indent: number - Left indent in inchesright_indent: number - Right indent in inchesfirst_line_indent: number - First line indent in inchesStyles:
Create a document with custom fonts and spacing:
{
"title": "Professional Report",
"title_format": {
"font_name": "Arial",
"font_size": 24,
"font_color": "#2E4053"
},
"paragraphs": [
{
"text": "Executive Summary",
"style": "Heading 1",
"font_name": "Arial",
"font_size": 18,
"font_color": "#1A5490"
},
{
"text": "This report provides key insights...",
"font_name": "Times New Roman",
"font_size": 12,
"line_spacing": 1.5,
"space_after": 10,
"first_line_indent": 0.5,
"alignment": "justify"
}
],
"tables": [
[
[
{"text": "Product", "bold": true, "font_size": 11},
{"text": "Revenue", "bold": true, "font_size": 11}
],
[
{"text": "Widget A", "font_name": "Arial"},
{"text": "$50,000", "font_color": "#27AE60"}
]
]
]
}
## Editing Word Documents
Modify existing Word documents with operations like find/replace, adding content, or updating metadata.
### Usage
```bash
python3 scripts/edit_word.py <input_path> <output_path> <operations_json>
Replace Text:
{
"type": "replace_text",
"old_text": "original text",
"new_text": "replacement text"
}
Add Paragraph:
{
"type": "add_paragraph",
"text": "New paragraph content",
"position": "start",
"style": "Normal"
}
Add Heading:
{
"type": "add_heading",
"text": "New Section",
"level": 1
}
Update Metadata:
{
"type": "update_metadata",
"metadata": {
"title": "New Title",
"author": "New Author"
}
}
Delete Paragraph:
{
"type": "delete_paragraph",
"index": 0
}
Format Specific Paragraph:
{
"type": "format_paragraph",
"index": 2,
"run_format": {
"font_name": "Arial",
"font_size": 14,
"bold": true,
"font_color": "#FF0000"
},
"paragraph_format": {
"alignment": "center",
"line_spacing": 1.5,
"space_after": 12
}
}
Format All Paragraphs:
{
"type": "format_all_paragraphs",
"run_format": {
"font_name": "Times New Roman",
"font_size": 12
},
"paragraph_format": {
"line_spacing": 1.5,
"first_line_indent": 0.5
}
}
Format Text Containing Specific String:
{
"type": "format_text_contains",
"search_text": "Important",
"run_format": {
"bold": true,
"font_color": "#FF0000",
"font_size": 14
},
"paragraph_format": {
"alignment": "center"
}
}
When user says "Replace all instances of 'draft' with 'final' in this document":
python3 scripts/edit_word.py input.docx output.docx '[{"type":"replace_text","old_text":"draft","new_text":"final"}]'
Multiple operations can be combined in a single array.
Convert Word documents to PDF, Markdown, HTML, or plain text.
python3 scripts/convert_format.py <input_path> <output_path> <format>
pip install docx2pdf) or LibreOfficeWhen user requests "Convert this Word document to PDF":
python3 scripts/convert_format.py report.docx report.pdf pdf
When user asks "Convert to Markdown so I can edit in a text editor":
python3 scripts/convert_format.py report.docx report.md markdown
Install required Python packages:
pip install python-docx
Optional dependencies for additional features:
# For .doc file support
brew install antiword # macOS
# or
pip install textract
# For PDF conversion
pip install docx2pdf
# or install LibreOffice
User: "What's in this Word file?"
python3 scripts/read_word.py file.docx --format markdownUser: "Create a Word document with these sections: Introduction, Methods, Results, Conclusion"
User: "Update the author name and add a new section to this document"
User: "Convert all my Word documents to PDF"
Scripts return JSON error messages with solutions when issues occur:
Always check script output for "success": true before confirming completion.