office_patch
Apply targeted edits to Word, Excel, or PowerPoint documents by specifying cell references, placeholders, or shape paths and new values in a list of changes.
Instructions
Apply edits to Word, Excel, or PowerPoint documents.
Accepts a list of changes and applies them to the document. Each change specifies a target (cell, shape, placeholder, section) and new value.
Replaces: excel_patch_cell, excel_patch_range, excel_replace_placeholders, word_patch_section, word_patch_placeholder, word_fix_split_placeholders, word_replace_global_variables, pptx_patch_shape, pptx_replace_text, pptx_replace_placeholders
Examples: # Patch Excel cells office_patch( file_path="data.xlsx", changes=[ {"target": "B5", "value": "New Value"}, {"target": "C10", "value": 42}, {"target": "D1", "value": "=SUM(A1:A10)"}, ] )
# Patch Excel range (multiple cells at once)
office_patch(
file_path="data.xlsx",
changes=[{"target": "A1:B3", "value": [["H1", "H2"], ["A", 1], ["B", 2]]}]
)
# Patch cells on a specific sheet (quote sheet names with special chars)
office_patch(
file_path="form.xlsm",
changes=[
{"target": "'ECIF Work Scope (E)'!B5", "value": "Contoso Ltd"},
{"target": "'ECIF Work Scope (E)'!B28", "value": "02/01/2026"},
]
)
# Replace placeholders in Word
office_patch(
file_path="template.docx",
changes=[
{"target": "<Customer Name>", "value": "Acme Corp"},
{"target": "<Date>", "value": "2026-01-23"},
]
)
# Patch PowerPoint shape
office_patch(
file_path="deck.pptx",
changes=[{"target": "slide:1/Title 1", "value": "New Title"}]
)
# Patch PowerPoint with soft return
office_patch(
file_path="deck.pptx",
changes=[{"target": "slide:1/Title 2", "value": "Contoso{br}Project"}]
)IMPORTANT for PowerPoint: When patching content placeholders (body, Content Placeholder), do NOT include bullet characters (•, -, *, etc.) in text lines. PowerPoint placeholders automatically render each line as a bullet. Including bullet characters causes duplication like '- • text'. Use newlines to separate items, and leading spaces (4 spaces) for indentation.
Args: file_path: Path to the document changes: List of changes, each a dict with "target" (cell ref, placeholder, or shape path) and "value" (new content, no bullet chars for PPTX body) track_changes: Log changes for audit trail (default True) output_path: Optional output path (defaults to overwriting input)
Returns: Dictionary with results of all changes. Each successful result includes a "value_preview" field with a truncated preview of the value applied.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the document | |
| changes | Yes | List of changes, each a dict with "target" (cell ref, placeholder, or shape path) and "value" (new content, no bullet chars for PPTX body) | |
| track_changes | No | Log changes for audit trail (default True) | |
| output_path | No | Optional output path (defaults to overwriting input) | |
| mode | No |