Edit a .docx
docx_editApply text, paragraph, and metadata edits to Microsoft Word .docx files, then write the updated document back in place or to a new path.
Instructions
Apply edits to a Microsoft Word .docx document and write the result back.
Call docx_read first to learn paragraph indices. All index values refer to the ORIGINAL
document as docx_read reported it — operations are applied together, so earlier operations
never shift the indices of later ones.
Operations:
{op:"replace_text", find, replace, all?} — replace text inside a paragraph, matching across formatting runs so the surrounding formatting is preserved. Works on the whole document unless you set
all:false, in which case only the first occurrence is replaced. A match spanning a tab or line break is refused; use replace_paragraph for those.{op:"replace_paragraph", index, text} — replace one paragraph's whole text, keeping the formatting of its first run.
{op:"insert_paragraph_after", index, text, style?} — insert a new paragraph after the given index; use index 0 to insert at the very start.
styletakes a style id such as Heading1.{op:"delete_paragraph", index} — remove a paragraph (inside a table it becomes an empty one, because a table cell must keep at least one paragraph).
{op:"set_metadata", title?, subject?, creator?, keywords?, description?, lastModifiedBy?} — update the document properties.
By default the file is modified in place, and the first in-place edit leaves a one-time backup next to it as ".orig.docx". Pass output_path to write elsewhere instead, or dry_run:true to see what would change without writing anything.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the .docx to modify. | |
| dry_run | No | Report what would change without writing anything. | |
| operations | Yes | Edits to apply, in order. | |
| output_path | No | Write the result here instead of modifying path in place. |