Edit Excel Values and Formulas
xl_editEdit Excel workbook values and formulas: set cells, write/clear/copy/move ranges, batch apply edits, find/replace, and import CSV/TSV/JSON with backups and atomic saves.
Instructions
Values and formulas: set one or many cells, write, clear, copy or move ranges, the batch editor (apply_edits), find and replace, and CSV, TSV or JSON import. A string starting with '=' is always stored as a formula. Formatting is xl_format; sheets, rows and tables are xl_structure. Every change backs the file up first, saves atomically and verifies after writing. Refuses a workbook open in Excel, and a workbook whose fragile parts a save would drop unless allow_loss is true. Ops, one per line, as name(required; opt optional): what it does. path, backup and verify_com are not repeated; xl_help shows them:
set_cell(location, value; opt sheet allow_loss): Write one cell by location; a string starting with '=' is always stored as a formula.
set_cells(cells; opt sheet echo_cells allow_loss): Write many individually addressed cells as ONE atomic batch, the scatter complement to write_range.
write_range(location, data; opt sheet parse_dates echo_cells allow_loss): Write a rectangular 2D block of values and formulas from the location's top-left cell; ragged rows are refused.
clear_range(location; opt what sheet allow_loss): Clear a cell or range: what='contents' removes values and formulas, 'formats' resets styles to default, 'all' does both.
copy_range(source, dest; opt what adjust_formulas sheet allow_loss): Copy a source rectangle to a destination anchor (location objects, may name different sheets).
move_range(source, dest; opt sheet allow_loss): Move a rectangle on the same sheet, rewriting every reference into it so references follow the cells.
apply_edits(edits; opt echo_cells allow_loss): Apply many addressed edits as ONE atomic batch.
replace_cells(find, replace; opt look_in match match_case sheet location dry_run formulas allow_loss): Find and replace across a workbook, sheet or range (exact, contains or regex); dry_run=true changes nothing. 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: - set_formula(location, formula; opt sheet echo_cells allow_loss): Write a formula to a cell, or fill a range with relative references shifted per cell; results stay stale until recalculated. - import_data(opt source source_file fmt location sheet header delimiter encoding formulas column_types parse_dates echo_cells allow_loss): Import CSV, TSV or JSON text or a file at a location; codes such as IDs and zip codes stay text, and the result says which columns. | |
| args | No | The op's arguments as an object. Include path (the workbook file) unless the op's line names other paths or the op reads no workbook; unknown keys are refused. xl_help lists every argument. |