Recipes
Safe cell patch
Patch a couple of cells and only write output when the mutated workbook still passes validation.
Open a workbook, patch a few cells, and let mutateWorkbookFile decide
whether the output is safe to write. This is the smallest possible safe
edit and the pattern every other recipe builds on.
import { mutateWorkbookFile, readWorkbookCell } from "@ironsheet/node";
const inputPath = "template.xlsx";
const outputPath = "patched.xlsx";
// mutateWorkbookFile is the recommended safe-write flow: it validates the
// mutated workbook and returns a package diff before committing bytes.
const report = await mutateWorkbookFile(inputPath, outputPath, async (workbook) => {
await workbook.patchCell("Sheet1", "A1", "Updated by Ironsheet");
await workbook.patchCell("Sheet1", "B2", 42000);
});
if (!report.wrote) {
throw new Error(`Output suppressed: ${report.validation.summary.errors} validation error(s)`);
}
console.log("wrote", outputPath);
console.log("validation summary", report.validation.summary);
console.log("package diff summary", report.diff.summary);
console.log("A1 is now", await readWorkbookCell(outputPath, "Sheet1", "A1"));What the report tells you
report.wrote—falsemeans Ironsheet refused to writeoutput.xlsxbecause the mutated workbook failed validation. The twopatchCellcalls above still ran in memory, but nothing hit disk.report.validation.summary— error and warning counts from the same validatorworkbook.validate()runs. Check this first whenwroteisfalse.report.diff.summary— the package-level diff. For a two-cell patch like this, expectchangedto reflect the worksheet part that now contains your edits, and everything else in the ZIP to come backunchanged.readWorkbookCellreads the value straight back out of the file you just wrote — a quick way to confirm the patch landed where you expect.
Only the targeted structures move
Because Ironsheet preserves untouched ZIP entries by default, patching two
cells in Sheet1 does not touch styles, charts, pivots, or any other
sheet in the workbook — the diff summary should confirm that directly
instead of you having to take it on faith.
Related
- Safe writes — the full
WorkbookSafeWriteReportreference. - Inspect and validate — read a workbook back out without mutating it.