Word Files and Assembly
word_documentCreate, copy, merge, split, template, mail-merge, protect, and export whole Word .docx files; manage backups, metadata, watermarks, accessibility fixes, and tables.
Instructions
Whole files: create, copy, assemble, split, templates, mail merge, backups, protection, watermark, document properties, accessibility fixes and table export. Edits inside one document belong to the other tools. Writes only the files named in args; manage_backups lists, restores and snapshots the automatic backups. Ops, one per line, as name(required; opt optional): what it does. file_path, live and backup are not repeated; word_help shows them:
insert_document(target_path, source_path; opt location formatting): Insert the ENTIRE body of source_path into target_path at one position, with full resource reconciliation: the chapter-merge tool.
copy_document(dest_path; opt overwrite): Copy a document byte for byte to dest_path; an existing destination is refused unless overwrite=true.
create_document(opt title): Create a new blank .docx, optionally with a title property; an existing file is refused.
manage_backups(action; opt file_path directory source scope dry_run label dest_dir): List, restore, purge or snapshot the automatic backups (prev and anchor slots); purge is a dry run unless dry_run=false.
set_document_properties(opt title author subject keywords category comments update_fields_on_open embed_fonts embed_fonts_subset): Set core document metadata (File > Info): title, author, subject, keywords, category, comments; only the parameters given change.
split_document(output_dir; opt level filename_from): Split a document into one standalone .docx per heading section, the inverse of com_multi_document merge (no Word needed).
copy_table(target_path, source_path, table_index; opt after_index after_text at_end): Copy one table from source_path into target_path, reconciling styles, numbering, images and notes; the source is not changed.
apply_template(reference_path; opt include_page_geometry): Restyle this document to match a reference document: styles, theme, fonts, layout settings, optionally page geometry. More ops follow, in the same format, in the op parameter's description.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| op | Yes | The operation to run: an op listed in this tool's description, or one of these, in the same format: - fill_template(data; opt missing): Fill a template IN PLACE: replace every {{name}} with data[name] (safe across fragmented runs, first run's formatting kept) and set MERGEFIELDs as plain text. - mail_merge(template_path, data_rows, output_dir; opt filename_pattern missing): Mail merge: one filled .docx per data row, saved into output_dir. - assemble_front_matter(spec): Insert front matter (title page, abstract, TOC, lists) at the start, numbered in roman numerals before the body. - set_document_protection(opt protection password restrict_formatting): Restrict editing, or lift the restriction. - set_watermark(watermark): Set or remove the page watermark. - fix_accessibility(opt alt_text_placeholders heading_skips heading_strategy table_headers doc_title dry_run): Repair validate(checks=['accessibility']) findings, one opted-in category at a time; all default OFF, none enabled refuses. - export_table(table_index; opt format output_path include_merges): Export one body-level table to CSV or JSON as a rows x grid-columns matrix. | |
| args | No | The op's arguments as an object. Include file_path (the absolute .docx path) unless the op's line names other paths or the op reads no document; unknown keys are refused. word_help lists every argument. |