ooxml-excel-editor 1.14.1 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +93 -22
- package/dist/chunks/{index-SuDQ4pfV.js → index-C0COOyM4.js} +4880 -4754
- package/dist/chunks/{index-BYG-8dM_.js → index-D63is84s.js} +3270 -3228
- package/dist/chunks/{index.es-BUtta4iJ.js → index.es-N4HpaZ5b.js} +1 -1
- package/dist/chunks/{index.es-CzHP2YBW.js → index.es-qiHokwgz.js} +1 -1
- package/dist/chunks/{jspdf.es.min-BOekb9jX.js → jspdf.es.min-DXY0IlZa.js} +2 -2
- package/dist/chunks/{jspdf.es.min-DpngVMOz.js → jspdf.es.min-Dg8neDb_.js} +2 -2
- package/dist/chunks/toolbar-icons-BvcaTxkJ.js +148 -0
- package/dist/core/edit/clipboard-write.d.ts +23 -0
- package/dist/core/export/xlsx-writer.d.ts +8 -1
- package/dist/core/index.d.ts +5 -2
- package/dist/core/open.d.ts +4 -0
- package/dist/core/parser/index.d.ts +1 -1
- package/dist/core.js +57 -52
- package/dist/index.js +80 -75
- package/dist/react.js +88 -83
- package/dist/vue2.js +58 -53
- package/package.json +1 -1
- package/dist/chunks/toolbar-icons-Daykg95B.js +0 -235
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
本项目遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 与 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## [1.15.1] - 2026-06-25
|
|
6
|
+
|
|
7
|
+
> 修非 HTTPS / 内网 IP 部署下复制静默失败。纯增量,HTTPS / localhost 行为字节级不变、零回归。
|
|
8
|
+
|
|
9
|
+
### 修复 — 复制兼容非安全上下文(内网 HTTP / 局域网 IP)
|
|
10
|
+
|
|
11
|
+
- **现象**:在 `http://192.168.x.x:port` 或内网 HTTP 域名访问时,右键菜单「复制」/ Ctrl+C 点了无反应。
|
|
12
|
+
- **根因**:复制(`ViewerController.copySelection` / `copyMultiSelection`)只用 `navigator.clipboard.write` / `writeText`,这俩受浏览器 Secure Context 约束 —— 非 HTTPS 且非 loopback 时 `navigator.clipboard` 为 `undefined`,`else` 分支调用直接抛 `TypeError`,被 `catch` 静默吞掉。内网部署的企业级应用(OKR/ERP/工单,普遍不挂 HTTPS)因此完全用不了复制。
|
|
13
|
+
- **修法**:新增框架无关 helper [`src/core/edit/clipboard-write.ts`](./src/core/edit/clipboard-write.ts) `writeClipboard(tsv, html?)` 双路径 —— ① 安全上下文仍走异步 Clipboard API(`ClipboardItem` 同时写 `text/plain` + `text/html`,**1:1 保真 / 图片 / 格式 / `data-ooxml-clip` 快照全不变**);② 不可用 / 抛异常时退到 `document.execCommand('copy')`,临时 `copy` 监听器照样 `setData` 双 MIME(富表格 + 内嵌快照仍能粘进 Excel/Word/本组件)。`copySelection` / `copyMultiSelection` 两处重复内联块收敛到此 helper。
|
|
14
|
+
- **影响**:HTTPS / localhost 用户走原路径,行为完全一致;内网 HTTP 用户从"复制无效"恢复为可用。纯 core 修复,Vue 3 / React / Vue 2 三壳零改动自动获得。
|
|
15
|
+
- 新增 [`src/core/edit/__tests__/clipboard-write.test.ts`](./src/core/edit/__tests__/clipboard-write.test.ts) 锁回归(安全上下文 / 内网兜底 / 无权限降级 / headless,4 测)。
|
|
16
|
+
|
|
17
|
+
## [1.15.0] - 2026-06-15
|
|
18
|
+
|
|
19
|
+
> 纯 Node(headless)用法闭环 —— 让"解析取数"与"高保真往返编辑"在无浏览器/无 canvas 的 Node 里好用。纯增量,默认行为不变、零回归。
|
|
20
|
+
|
|
21
|
+
### 新增 — Node 友好的入口 / 出口(框架无关 core)
|
|
22
|
+
|
|
23
|
+
- **`openWorkbook(src)`**:一行门面 = `loadArrayBuffer` 归一化 + `parseWorkbook`,Node 可直接吃 `fs.readFileSync()` 的 **Buffer**(Buffer 是 Uint8Array 子类),浏览器侧仍接受 File/Blob/ArrayBuffer/URL。
|
|
24
|
+
- **`parseWorkbook` 放宽入参** 为 `ArrayBuffer | Uint8Array` 并在内部归一化 —— 老 ArrayBuffer 调用 100% 兼容,Node 传 Buffer/Uint8Array 不再 TS 报错或踩坑。
|
|
25
|
+
- **`workbookToXlsxBytes(wb, opts)`**:返回 `Uint8Array`(不是浏览器 `Blob`),纯 Node `fs.writeFileSync` 直接落盘;`fidelity: 'overlay' + sourceBuffer` 保真往返。`workbookToXlsxBlob` 改为它 + Blob 包装,签名/行为不变。
|
|
26
|
+
- **导出建表 API**:`jsonToWorkbook` / `isWorkbookModel` / `makeDefaultStyle`(及 `JsonInput`/`JsonLoadOptions` 类型)补进 core 出口 —— 可在 Node 从数据(2D 数组 / 对象数组)直建模型再 `workbookToXlsxBytes` 生成 .xlsx。四入口同源,各壳自动可见。
|
|
27
|
+
|
|
28
|
+
### 文档 / 示例 / 测试
|
|
29
|
+
|
|
30
|
+
- README 新增 **「Node / 服务端 (headless) 用法」** 节(取数 / 高保真往返 / 数据建表三段可跑代码 + headless 不可用清单);英文区加对应段。EXTENDING.md 加 **「Headless / Node 安全 API 面」**(纯 Node 可用 vs 需浏览器的导出清单)。
|
|
31
|
+
- **修正过时安装文档**:`exceljs` / `fflate` / `jspdf` / `hyperformula` 1.3.2+ 已**内联进 dist**,README 各处 `npm i ... exceljs` → 去掉(只需装 framework;纯 Node 仅 `npm i ooxml-excel-editor`)。入口表 peer 列 + "exceljs 为 peer" 旧述一并更正。
|
|
32
|
+
- 新增 [`examples/node-extract.mjs`](./examples/node-extract.mjs) / [`examples/node-roundtrip.mjs`](./examples/node-roundtrip.mjs) 可跑示例;新增 `src/core/__tests__/node-headless.test.ts` 回归网(openWorkbook 吃 Buffer / 取数 / 往返 bytes / 数据建表,5 测)。
|
|
33
|
+
|
|
5
34
|
## [1.14.1] - 2026-06-15
|
|
6
35
|
|
|
7
36
|
> 文档审计 + 入口出口修正(无运行时行为变更)。一次"保证接入/二开都没问题"的体检。
|
package/README.md
CHANGED
|
@@ -64,43 +64,96 @@ const src = ref<File>() // 绑个 <input type="file" @change> 给它即可
|
|
|
64
64
|
|
|
65
65
|
## 安装
|
|
66
66
|
|
|
67
|
-
一个包,**四个子入口** —— 框架无关的 core 引擎被 Vue 3 / React 两个壳共享(`dist/core.js` 只打一份),Vue 2 因 SFC 编译器跟 Vue 3 冲突独立打包(内嵌 core)
|
|
67
|
+
一个包,**四个子入口** —— 框架无关的 core 引擎被 Vue 3 / React 两个壳共享(`dist/core.js` 只打一份),Vue 2 因 SFC 编译器跟 Vue 3 冲突独立打包(内嵌 core)。**只需按框架装对应 framework**,`exceljs` / `fflate` / `jspdf` / `hyperformula` 等重依赖 **1.3.2+ 已内联进 dist,无需手动装**:
|
|
68
68
|
|
|
69
69
|
```bash
|
|
70
70
|
# Vue 3 项目
|
|
71
|
-
npm i ooxml-excel-editor vue
|
|
71
|
+
npm i ooxml-excel-editor vue
|
|
72
72
|
|
|
73
73
|
# React 项目
|
|
74
|
-
npm i ooxml-excel-editor react react-dom
|
|
74
|
+
npm i ooxml-excel-editor react react-dom
|
|
75
75
|
|
|
76
76
|
# Vue 2.6.x 或 2.7+ 项目 (1.3.0+) — 必装 @vue/composition-api (兼容 2.6 + 2.7)
|
|
77
|
-
npm i ooxml-excel-editor vue@2.7 @vue/composition-api
|
|
77
|
+
npm i ooxml-excel-editor vue@2.7 @vue/composition-api
|
|
78
78
|
# Vue 2.6.x 还需 main.js: Vue.use(require('@vue/composition-api').default)
|
|
79
79
|
|
|
80
|
-
#
|
|
81
|
-
npm i ooxml-excel-editor
|
|
82
|
-
|
|
83
|
-
# echarts 可选:仅渲染图表时需要;jspdf 可选:仅导出 PDF 时需要
|
|
84
|
-
npm i echarts jspdf
|
|
85
|
-
# hyperformula 可选:仅开启编辑 + 公式重算(recalc)时需要
|
|
86
|
-
npm i hyperformula
|
|
80
|
+
# 纯 Node / 只解析读数据 / 导出(不渲染 UI,无框架)
|
|
81
|
+
npm i ooxml-excel-editor
|
|
87
82
|
```
|
|
88
83
|
|
|
89
84
|
四个入口:
|
|
90
85
|
|
|
91
|
-
| import | 内容 |
|
|
86
|
+
| import | 内容 | 需要装的 framework | 体积 (gzip) |
|
|
92
87
|
|---|---|---|---|
|
|
93
|
-
| `ooxml-excel-editor` | **Vue 3** 组件 `<ExcelViewer>` (参考实现 Standard) | `vue@3`
|
|
94
|
-
| `ooxml-excel-editor/react` | **React** 组件 `<ExcelViewer>` (1:1 复刻 Vue 3) | `react` + `react-dom`
|
|
95
|
-
| `ooxml-excel-editor/vue2` | **Vue 2.6 / 2.7+** 组件 `<ExcelViewer>` (1:1 复刻 Vue 3) | `vue@2.6+` + `@vue/composition-api`
|
|
96
|
-
| `ooxml-excel-editor/core` | 框架无关引擎(解析/渲染/控制器/导出/读数据) |
|
|
88
|
+
| `ooxml-excel-editor` | **Vue 3** 组件 `<ExcelViewer>` (参考实现 Standard) | `vue@3` | ~19 KB + 共享 chunks |
|
|
89
|
+
| `ooxml-excel-editor/react` | **React** 组件 `<ExcelViewer>` (1:1 复刻 Vue 3) | `react` + `react-dom` | ~11 KB + 共享 chunks |
|
|
90
|
+
| `ooxml-excel-editor/vue2` | **Vue 2.6 / 2.7+** 组件 `<ExcelViewer>` (1:1 复刻 Vue 3) | `vue@2.6+` + `@vue/composition-api` | ~124 KB (内嵌 core) |
|
|
91
|
+
| `ooxml-excel-editor/core` | 框架无关引擎(解析/渲染/控制器/导出/读数据) | 无(纯 Node 也可用,见 [Node 用法](#node--服务端-headless-用法)) | ~1 KB + 共享 chunks |
|
|
97
92
|
|
|
98
|
-
`
|
|
93
|
+
`vue` / `react` / `vue@2` 按框架三选一(均为可选 peer);`exceljs` / `fflate` / `jspdf` / `hyperformula` **已内联进 dist**(无需装、也**绝不重复进你的产物**,运行时才动态从 chunk 加载);`echarts` 是 external 依赖(npm 自动装,仅图表渲染才真正加载,避免主题 dual instance)。
|
|
99
94
|
|
|
100
95
|
> **三壳 UI 1:1**: Vue 3 SFC 是参考实现 (Standard), Vue 2 / React 1:1 复刻视觉与交互 (工具栏 SVG 图标 / 下拉子菜单 / 公式栏 / 状态栏 / dialog / 浮层 / 演示 demo 全部对齐). 详见 [docs/Vue2.md](./docs/Vue2.md) 跟 Vue 3 的差异速查 + [CLAUDE.md](./CLAUDE.md) 第 7 中心原则。
|
|
101
96
|
|
|
102
97
|
> 公式重算的引擎(1.14.0 起):默认是**内置 MIT 引擎**(零依赖,覆盖 ~60 常用函数,无许可证负担)。需要更全函数集时,`formulaEngine` prop 注入 **HyperFormula**(`hyperFormulaEngineFactory`,GPL-3.0/商业双授权,~395 函数)或自研引擎(实现 `FormulaEngine` 接口)。
|
|
103
98
|
|
|
99
|
+
## Node / 服务端 (headless) 用法
|
|
100
|
+
|
|
101
|
+
不渲染 UI、纯在 **Node**(无浏览器、无 canvas)里处理 .xlsx —— 走 `ooxml-excel-editor/core`(框架无关、ESM)。装包只需 `npm i ooxml-excel-editor`(`exceljs` 等已内联)。可跑示例见 [`examples/`](./examples)。
|
|
102
|
+
|
|
103
|
+
**适合 Node 的两件事**(比裸 `exceljs` 多了"显示文本渲染 / 合并 / 日期 / 富文本"的保真):
|
|
104
|
+
|
|
105
|
+
**① 解析取数** —— 拿"人看到的"数据(显示文本 / JSON / CSV):
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { readFileSync } from 'node:fs'
|
|
109
|
+
import { openWorkbook, getSheetData, sheetToJSON, getCellText, toCsv } from 'ooxml-excel-editor/core'
|
|
110
|
+
|
|
111
|
+
// openWorkbook 直接吃 Node Buffer —— 不必手动转 ArrayBuffer
|
|
112
|
+
const wb = await openWorkbook(readFileSync('input.xlsx'))
|
|
113
|
+
const sheet = wb.sheets[0]
|
|
114
|
+
|
|
115
|
+
getCellText(sheet, 0, 0) // 单格显示文本(数字格式/日期已渲染,如 "2021年1月")
|
|
116
|
+
getSheetData(sheet, { format: true }) // 2D 数组(format:false 给原始值)
|
|
117
|
+
sheetToJSON(sheet) // 对象数组(首行当表头)
|
|
118
|
+
toCsv(sheet) // CSV 文本
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**② 高保真往返编辑** —— 打开真实 .xlsx → 程序化改值/样式 → 保样式回写(`overlay` 保留原件的样式/条件格式/图片/透视表,裸 exceljs 会丢):
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
125
|
+
import { openWorkbook, setCellValue, applyStyleOverride, workbookToXlsxBytes } from 'ooxml-excel-editor/core'
|
|
126
|
+
|
|
127
|
+
const src = readFileSync('input.xlsx')
|
|
128
|
+
const wb = await openWorkbook(src)
|
|
129
|
+
const sheet = wb.sheets[0]
|
|
130
|
+
|
|
131
|
+
setCellValue(sheet, 1, 2, 123.45)
|
|
132
|
+
applyStyleOverride(sheet, 1, 2, { font: { bold: true, color: '#FF0000' } })
|
|
133
|
+
|
|
134
|
+
// workbookToXlsxBytes 返回 Uint8Array(不是浏览器 Blob),直接 fs 落盘
|
|
135
|
+
const bytes = await workbookToXlsxBytes(wb, {
|
|
136
|
+
fidelity: 'overlay',
|
|
137
|
+
sourceBuffer: src.buffer.slice(src.byteOffset, src.byteOffset + src.byteLength),
|
|
138
|
+
})
|
|
139
|
+
writeFileSync('output.xlsx', bytes)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**③ 从数据建表**(可选;纯建表裸 `exceljs` 也行)—— `jsonToWorkbook` → `workbookToXlsxBytes`:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { writeFileSync } from 'node:fs'
|
|
146
|
+
import { jsonToWorkbook, workbookToXlsxBytes } from 'ooxml-excel-editor/core'
|
|
147
|
+
|
|
148
|
+
const wb = jsonToWorkbook(
|
|
149
|
+
[{ name: '张三', age: 25 }, { name: '李四', age: 30 }],
|
|
150
|
+
{ sheetName: 'People' },
|
|
151
|
+
)
|
|
152
|
+
writeFileSync('new.xlsx', await workbookToXlsxBytes(wb))
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Node headless 下不可用**(硬依赖浏览器 canvas / DOM,需在浏览器或 Electron 渲染进程跑):图片/PNG/JPEG 与 **PDF 导出**、`print()`、`downloadBlob`、内置 `DefaultEditor` 编辑器、`<ExcelViewer>` 组件渲染。另:`finalizeImages` 在 Node 会安全跳过(图片保留 `bytes`/`mime`,不生成 blob URL);URL 字符串入参走 `fetch`,**Node 用 `fs` 读 Buffer,别传本地路径字符串**。纯 Node 可用的导出面见 [EXTENDING.md](./EXTENDING.md#headless--node-安全-api-面)。
|
|
156
|
+
|
|
104
157
|
## 使用
|
|
105
158
|
|
|
106
159
|
### Vue
|
|
@@ -339,12 +392,12 @@ viewer.value.getRangeData(viewer.value.getSelection()) // 取"我选中的"区
|
|
|
339
392
|
|---|---|
|
|
340
393
|
| `ExcelViewer` | 预览/编辑组件(各框架入口各自的) |
|
|
341
394
|
| `default` | Vue 3 / Vue 2 入口默认导出 = Vue 插件(`app.use`) |
|
|
342
|
-
| **解析/加载** | `parseWorkbook(buffer)`(`ArrayBuffer → Promise<WorkbookModel>`,优先 Worker)· `loadArrayBuffer(src)`(多种输入归一) |
|
|
395
|
+
| **解析/加载** | `openWorkbook(src)`(一行门面 = 归一化 + 解析,Node/浏览器通用)· `parseWorkbook(buffer)`(`ArrayBuffer\|Uint8Array → Promise<WorkbookModel>`,优先 Worker)· `loadArrayBuffer(src)`(多种输入归一)· `jsonToWorkbook(data)`(数据直建模型) |
|
|
343
396
|
| **读数据 API** | `getCellValue` / `getCellText` / `getCellStyle` / `getSheetData` / `getRangeData` / `sheetToJSON` / `getWorkbookJSON` / `cellDisplayText` |
|
|
344
397
|
| **格式/工具** | `formatValue`(数字格式)· `cellKey` · `colIndexToLetters` |
|
|
345
398
|
| **插件 / 主题** | `definePlugin` · `DEFAULT_THEME` / `mergeTheme` |
|
|
346
399
|
| **公式引擎**(1.14.0) | `builtinFormulaEngineFactory`(默认,MIT)· `hyperFormulaEngineFactory`(HyperFormula,GPL/商业)· `FUNCTION_NAMES`(已支持函数名)· `BuiltinFormulaEngine` |
|
|
347
|
-
| **导出工具** | `workbookToXlsxBlob` · `toCsv` / `toWorkbookJson` · `canvasToBlob` / `canvasToDataURL` / `downloadBlob` |
|
|
400
|
+
| **导出工具** | `workbookToXlsxBytes`(→ `Uint8Array`,**纯 Node 落盘用**)· `workbookToXlsxBlob`(→ `Blob`,浏览器下载用)· `toCsv` / `toWorkbookJson` · `canvasToBlob` / `canvasToDataURL` / `downloadBlob`(后三者需浏览器) |
|
|
348
401
|
| **类型** | `WorkbookModel` / `SheetModel` / `CellModel` / `CellStyle` / `CellStyleOverride` / `MergeRange` / `ConditionalRule` / `DataValidationRule` / `ChartSpec` / `ImageAnchor` / `PivotTableModel` / `CssColor` / `ExcelSource` / `ViewerApi` / `ExcelPlugin` / `FormulaEngine` / `FormulaEngineFactory` / `EditConfig` / 导出选项类型(`PdfExportOptions`/`ImageExportOptions`/…)等 |
|
|
349
402
|
|
|
350
403
|
> 想看完整出口清单见 [`src/core/index.ts`](src/core/index.ts);深度二开(直接用 `ViewerController` / `CanvasRenderer` / `EditController` / 模型 mutations 等内部件)也都从这些入口导出,见 [ARCHITECTURE.md](ARCHITECTURE.md)。
|
|
@@ -480,7 +533,7 @@ const myEditor: EditorResolver = (cell, pos) => {
|
|
|
480
533
|
|
|
481
534
|
现代浏览器(Chrome/Edge 80+、Safari 15+、Firefox 114+,需支持 Canvas / ResizeObserver)。
|
|
482
535
|
|
|
483
|
-
> **解析线程**:发布的组件库在**主线程**解析(`exceljs`
|
|
536
|
+
> **解析线程**:发布的组件库在**主线程**解析(`exceljs` 1.3.2+ 已内联进 dist chunks,运行时动态加载,不重复进你的产物)。本仓库的 demo/dev 额外启用了 **Web Worker** 解析(大文件不卡 UI)。如果你的应用要处理很大的文件,可直接用导出的 `parseWorkbook` 包进你自己的 Worker。
|
|
484
537
|
|
|
485
538
|
## 范围边界
|
|
486
539
|
|
|
@@ -530,10 +583,10 @@ MIT
|
|
|
530
583
|
|
|
531
584
|
**🔗 Live demo: https://ojadeveloper.github.io/ooxml-excel-editor/**
|
|
532
585
|
|
|
533
|
-
A **Vue 3 + Vue 2 + React high-fidelity `.xlsx` preview & edit component** with a from-scratch parser and canvas renderer. Renders cells, number formats, merges, conditional formatting, images, charts (via ECharts), sparklines, comments, data validation, frozen panes, and supports selection / copy / hyperlinks. **Read-only by default**; set `editable` to enable editing — cell values / styles / column-row sizes / floating images / insert-delete rows-cols, with undo-redo, before/after full-snapshot events, dirty tracking + reset-to-original, swappable formula recalc engine, custom cell editors, and **export back to .xlsx / JSON / CSV**. Parsing runs in a Web Worker (with main-thread fallback). `vue` / `react`
|
|
586
|
+
A **Vue 3 + Vue 2 + React high-fidelity `.xlsx` preview & edit component** with a from-scratch parser and canvas renderer. Renders cells, number formats, merges, conditional formatting, images, charts (via ECharts), sparklines, comments, data validation, frozen panes, and supports selection / copy / hyperlinks. **Read-only by default**; set `editable` to enable editing — cell values / styles / column-row sizes / floating images / insert-delete rows-cols, with undo-redo, before/after full-snapshot events, dirty tracking + reset-to-original, swappable formula recalc engine, custom cell editors, and **export back to .xlsx / JSON / CSV**. Parsing runs in a Web Worker (with main-thread fallback). Only the framework (`vue` / `react`) is a peer dependency; `exceljs` / `fflate` / `jspdf` / `hyperformula` are bundled into `dist` (no manual install).
|
|
534
587
|
|
|
535
588
|
```bash
|
|
536
|
-
npm i ooxml-excel-editor vue
|
|
589
|
+
npm i ooxml-excel-editor vue
|
|
537
590
|
```
|
|
538
591
|
|
|
539
592
|
```ts
|
|
@@ -541,4 +594,22 @@ import { ExcelViewer } from 'ooxml-excel-editor'
|
|
|
541
594
|
import 'ooxml-excel-editor/style.css'
|
|
542
595
|
```
|
|
543
596
|
|
|
597
|
+
**Headless / Node (no browser):** use `ooxml-excel-editor/core` to parse `.xlsx`, extract data, edit and write back — no canvas needed. `npm i ooxml-excel-editor` only.
|
|
598
|
+
|
|
599
|
+
```ts
|
|
600
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
601
|
+
import { openWorkbook, sheetToJSON, setCellValue, workbookToXlsxBytes } from 'ooxml-excel-editor/core'
|
|
602
|
+
|
|
603
|
+
const src = readFileSync('input.xlsx')
|
|
604
|
+
const wb = await openWorkbook(src) // accepts a Node Buffer directly
|
|
605
|
+
const rows = sheetToJSON(wb.sheets[0]) // array of row objects (display text)
|
|
606
|
+
setCellValue(wb.sheets[0], 1, 2, 123.45)
|
|
607
|
+
writeFileSync('out.xlsx', await workbookToXlsxBytes(wb, {
|
|
608
|
+
fidelity: 'overlay',
|
|
609
|
+
sourceBuffer: src.buffer.slice(src.byteOffset, src.byteOffset + src.byteLength),
|
|
610
|
+
})) // workbookToXlsxBytes → Uint8Array (not a Blob)
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
Not available headless (need a browser canvas/DOM): image/PDF export, `print()`, the built-in cell editor, and component rendering. See the 中文 [Node 用法](#node--服务端-headless-用法) section for details.
|
|
614
|
+
|
|
544
615
|
See the API table above. MIT licensed.
|