XLSX
Patching
Modify an existing .xlsx through canonical WorkbookOptions commands
patchWorkbook parses an existing .xlsx into WorkbookOptions, applies ordered commands, and regenerates the package. Worksheet order, shared strings, and workbook sheet definitions are reconciled after worksheet commands.
import { patchWorkbook } from "@office-open/xlsx";
const result = await patchWorkbook({
data: workbook,
commands: [
{
type: "replace",
at: { field: "worksheets", route: [{ name: "Invoice" }], text: { placeholder: "customer" } },
value: "Acme Corporation",
},
{
type: "update",
at: { field: "worksheets", route: [{ name: "Invoice" }] },
set: { state: "hidden" },
},
{
type: "insert",
at: { field: "worksheets", route: [{ name: "Invoice" }, { collection: "comments" }] },
value: [{ cell: "A1", author: "Jane Doe", text: "Check this value" }],
},
],
});
Worksheet routes accept name or sheetId; cells and rows are addressed through canonical reference, address, index, and property routes. Set packageVariant for macro and template workbooks.
#Options
| Option | Type | Default |
|---|---|---|
data | DataType | required |
commands | readonly WorkbookPatchCommand[] | required |
outputType | OutputType | "uint8array" |
packageVariant | "standard" | "macro" | "template" | "macroTemplate" | "standard" |
placeholderDelimiters | { start, end } | { start: "{{", end: "}}" } |