Editing files
Change an existing workbook, document or deck with a validated plan. The parts the plan does not touch stay byte-identical.
edit_workbook, edit_document and edit_deck take the path of an existing file and a plan: a list of operations. The file keeps its styles, layouts and every part the plan does not touch, byte for byte, including parts this package does not know about.
{
"path": "budget-vs-actual.xlsx",
"plan": {
"ops": [
{ "op": "set_cell", "sheet": "Q3 2026", "column": "Actual", "row": "Marketing", "value": 26500 },
{ "op": "insert_rows", "sheet": "Q3 2026", "before": "Travel", "values": [["Insurance", 4000, 4100]] }
]
},
"dryRun": true
}Dry run, no file written. The plan would make these changes:
- 1. 'Q3 2026'!C9 (Actual / Marketing): "31900" -> "26500"
- 2. 'Q3 2026': inserted 1 row at row 11; 14 formulas and 3 ranges shifted; 3 formulas filled down from row 10
- recalculated with LibreOffice: 9 cached formula results updated
- 4 chart caches refreshed
Parts changed: xl/worksheets/sheet1.xml, xl/sharedStrings.xml, xl/drawings/drawing1.xml, xl/charts/chart1.xml; 16 parts untouched byte for byte.- Anchors by meaning. Cells by
ref, or by column header and row label. Document edits anchor on text, headings and placeholders; deck edits on slides and placeholders. - Dry run.
dryRun: truereports the changes and writes nothing. - Near misses. An anchor that is not found comes back with the closest matches, so the model can correct the plan:
No row labelled "Marketin", withMarketingamong the candidates. - Where it goes. By default the edit is a new file next to the made files. With
inPlace, the file is overwritten and the original is kept once as<name>.bak.<ext>.
Workbooks
| Op | What it does |
|---|---|
set_cell | A value, formula or style patch, by ref or by column header and row label. YYYY-MM-DD text becomes a date |
insert_rows, delete_rows | Formulas on every sheet, shared formulas, ranges, merged cells, defined names, tables, conditional formats, validations, charts, comments and drawings follow. New rows take the formats and formulas of the row above. References to deleted rows become #REF! and are reported |
add_sheet | A sheet spec, with its styles, strings, tables and charts merged into the workbook |
rename_sheet | Every formula, name, chart and hyperlink that names the sheet follows |
After the ops, formulas are recalculated with LibreOffice when it is installed and only the cached values are copied back; otherwise the file asks Excel to recalculate on open. Chart caches over edited sheets are refreshed.
Documents
| Op | What it does |
|---|---|
replace_text | Across split runs, keeping each run's formatting; all, matchCase, within a section |
fill_placeholders | {{Name}} and [[Name]] in the body, tables, headers and footers |
insert_blocks | Document spec blocks (headings, paragraphs, lists, tables, page breaks) before or after a paragraph or at the end of a section, in the document's own heading styles, numbering and table style |
delete_section, delete_paragraph, replace_paragraph | Remove or replace by heading or paragraph text |
track: { author } records every op as Word tracked changes.
Decks
| Op | What it does |
|---|---|
replace_text, set_text | On a placeholder or shape, keeping formatting and paragraph levels |
add_slide | A deck spec slide (title, bullets, two columns, table, chart, stat, section, closing) on the deck's own layouts; charts take the theme's colours |
delete_slide, move_slide | Relationships, notes, sections and unused parts follow |
update_chart | Categories and series, with the chart caches and the embedded workbook |
The full plan schemas are in the tools reference.
Limits
No column insert or delete. Tracked changes in Word only. Scatter and bubble charts cannot be updated, and imageText slides cannot be added. Encrypted and legacy binary files are rejected.
In code
import { readFile, writeFile } from "node:fs/promises";
import { editWorkbook } from "@vatsonai/office-edit";
const result = await editWorkbook(await readFile("budget.xlsx"), {
ops: [
{ op: "set_cell", sheet: "Q3", column: "Actual", row: "Marketing", value: 26500 },
{ op: "insert_rows", sheet: "Q3", before: "Travel", values: [["Insurance", 4000, 4100]] },
],
});
if (result.ok) await writeFile("budget-edited.xlsx", result.bytes!);
else console.log(result.error, result.candidates);editDocument and editDeck work the same way. outlineWorkbook, outlineDocument and outlineDeck list the anchors a plan can use.