| name | docx-create |
| description | DOCX: Create a new Word document with headings, paragraphs, tables, and lists. |
| metadata | {"version":"0.22.0","openclaw":{"category":"productivity","requires":{"bins":["python"]}},"maxent":{"requires":{"bins":[{"name":"python","install":{"windows":{"method":"winget","id":"Python.Python.3"},"linux":{"method":"apt","id":"python3"},"darwin":{"method":"brew","id":"python"}}}]}}} |
docx-create
PREREQUISITE: Ensure python-docx is installed: pip install python-docx
Create a new .docx Word document with headings, paragraphs, tables, and lists.
Usage
python - <<'EOF'
from docx import Document
doc = Document()
doc.add_heading("My Document", level=0)
doc.add_paragraph("First paragraph.")
doc.save("output.docx")
EOF
Recipes
Document with headings and paragraphs
python - <<'EOF'
from docx import Document
doc = Document()
doc.add_heading("Project Report", level=0)
doc.add_heading("Introduction", level=1)
doc.add_paragraph("This report covers the Q1 results.")
doc.add_heading("Details", level=2)
doc.add_paragraph("See the table below for a breakdown.")
doc.save("report.docx")
EOF
Document with a table
python - <<'EOF'
from docx import Document
doc = Document()
doc.add_heading("Sales Data", level=0)
table = doc.add_table(rows=1, cols=3)
table.style = "Table Grid"
hdr = table.rows[0].cells
hdr[0].text = "Name"
hdr[1].text = "Region"
hdr[2].text = "Revenue"
data = [("Alice", "North", "$120k"), ("Bob", "South", "$95k")]
for name, region, revenue in data:
row = table.add_row().cells
row[0].text = name
row[1].text = region
row[2].text = revenue
doc.save("sales.docx")
EOF
Document with a bulleted list
python - <<'EOF'
from docx import Document
doc = Document()
doc.add_heading("Action Items", level=1)
for item in ["Fix the login bug", "Write unit tests", "Deploy to staging"]:
doc.add_paragraph(item, style="List Bullet")
doc.save("actions.docx")
EOF
Document with a numbered list
python - <<'EOF'
from docx import Document
doc = Document()
doc.add_heading("Steps", level=1)
for step in ["Clone the repo", "Install dependencies", "Run the server"]:
doc.add_paragraph(step, style="List Number")
doc.save("steps.docx")
EOF
Document with bold/italic runs
python - <<'EOF'
from docx import Document
doc = Document()
para = doc.add_paragraph()
para.add_run("Important: ").bold = True
para.add_run("this part is italic.").italic = True
doc.save("styled.docx")
EOF
Set document metadata
python - <<'EOF'
from docx import Document
from datetime import datetime
doc = Document()
doc.core_properties.title = "Q1 Report"
doc.core_properties.author = "Jane Doe"
doc.core_properties.subject = "Quarterly Results"
doc.add_paragraph("Content here.")
doc.save("report.docx")
EOF
Tips
level=0 in add_heading renders as the document Title style; levels 1–9 are Heading 1–9.
table.style = "Table Grid" adds visible borders; omit for a borderless table.
- Always call
doc.save(path) at the end — nothing is written until then.
- Overwriting an existing file is silent; check the path before saving if preservation is needed.
[!CAUTION]
This is a write command — confirm with the user before executing.
See Also
- docx-read — Read content from a Word document
- docx-edit — Modify an existing Word document