XLSX
补丁修改
通过 WorkbookOptions canonical 命令修改现有 .xlsx
patchWorkbook 先把 .xlsx 解析成 WorkbookOptions,再按顺序执行命令并重新生成包。工作表命令执行后会同步 reconcile 工作表顺序、共享字符串和工作表定义。
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" }],
},
],
});
工作表路由支持 name 和 sheetId;单元格和行通过 canonical 的 reference、address、index、属性路由定位。宏工作簿和模板工作簿需要设置 packageVariant。
#选项
| 选项 | 类型 | 默认值 |
|---|---|---|
data | DataType | 必填 |
commands | readonly WorkbookPatchCommand[] | 必填 |
outputType | OutputType | "uint8array" |
packageVariant | "standard" | "macro" | "template" | "macroTemplate" | "standard" |
placeholderDelimiters | { start, end } | { start: "{{", end: "}}" } |