Word Media, Fields and Forms
word_mediaInsert, replace, export, and edit images, charts, equations, hyperlinks, fields, and form controls in Word .docx files while preserving backups and atomic saves.
Instructions
Embedded objects: images, charts, equations, text boxes, hyperlinks, fields, form fields and content controls. Plain text is word_edit and tables are word_structure. Every edit backs the file up first and saves atomically. These ops refuse a document open in Word. 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_image(image_path; opt location width_pt alignment wrap position z_order allow_overlap distance_pt wrap_text): Insert a PNG, JPEG, GIF, BMP or TIFF image at a location, inline by default or floating with wrap; aspect ratio is kept.
insert_field(field_code, location; opt placeholder): Insert a Word field (DATE, PAGE, NUMPAGES, SEQ, ...) at a location; codes outside the safe allowlist are refused.
set_image(image_id; opt source width_pt alt_text alt_title wrap position z_order allow_overlap distance_pt wrap_text force track author keep_width): Change one image (image_id from list_elements): swap the file (a tracked swap with track=true), resize, set alt text or wrapping; anything not named stays.
export_images(output_dir; opt prefix): Save every image in the document as files in output_dir; existing files are refused and the document is not changed.
insert_chart(chart_type, data; opt title width_pt height_pt location alignment legend colors): Insert a native, theme-following Word chart from data.
set_chart_data(chart_id, data; opt series_names): Replace a chart's data in place (chart_id from list_elements), keeping its formatting; the number of series must stay the same.
insert_equation(latex; opt display location at_text occurrence): Insert a LaTeX equation as NATIVE, editable Word math.
set_textbox_text(box_index, text): Replace the text of one text box (box_index from get_text(textbox=true)). 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: - insert_hyperlink(at_text, url; opt occurrence allow_local_file): Turn existing text (the occurrence-th match of at_text) into an external hyperlink; text already in a link is refused. - insert_content_control(tag, after_text; opt alias text occurrence): Insert a plain-text content control with a unique tag right after after_text; other control types are refused. - set_content_control(value; opt tag index): Set one content control's value, addressed by tag or by list_elements(type='content_controls') index (exactly one). - set_form_fields(values; opt missing): Set form-field values by name (legacy fields) or tag/alias (content controls): text fields take strings, checkboxes booleans, dropdowns only their options. | |
| 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. |