@cj-tech-master/excelts 1.6.3-canary.20251224124621.73c5d94 → 1.6.3-canary.20251224125850.7da664f
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/README.md +105 -4
- package/README_zh.md +105 -4
- package/dist/browser/excelts.esm.js +1 -1
- package/dist/browser/excelts.esm.min.js +1 -1
- package/dist/browser/excelts.iife.js +1 -1
- package/dist/browser/excelts.iife.min.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -104,6 +104,108 @@ cell.fill = {
|
|
|
104
104
|
- Data protection
|
|
105
105
|
- Comments and notes
|
|
106
106
|
|
|
107
|
+
## Streaming API (Node.js)
|
|
108
|
+
|
|
109
|
+
For processing large Excel files without loading them entirely into memory, ExcelTS provides streaming reader and writer APIs.
|
|
110
|
+
|
|
111
|
+
### Streaming Reader
|
|
112
|
+
|
|
113
|
+
Read large XLSX files with minimal memory usage:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import { WorkbookReader } from "@cj-tech-master/excelts";
|
|
117
|
+
|
|
118
|
+
// Read from file path
|
|
119
|
+
const reader = new WorkbookReader("large-file.xlsx", {
|
|
120
|
+
worksheets: "emit", // emit worksheet events
|
|
121
|
+
sharedStrings: "cache", // cache shared strings for cell values
|
|
122
|
+
hyperlinks: "ignore", // ignore hyperlinks
|
|
123
|
+
styles: "ignore" // ignore styles for faster parsing
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
for await (const worksheet of reader) {
|
|
127
|
+
console.log(`Reading: ${worksheet.name}`);
|
|
128
|
+
for await (const row of worksheet) {
|
|
129
|
+
console.log(row.values);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Streaming Writer
|
|
135
|
+
|
|
136
|
+
Write large XLSX files row by row:
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
import { WorkbookWriter } from "@cj-tech-master/excelts";
|
|
140
|
+
|
|
141
|
+
const workbook = new WorkbookWriter({
|
|
142
|
+
filename: "output.xlsx",
|
|
143
|
+
useSharedStrings: true,
|
|
144
|
+
useStyles: true
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const sheet = workbook.addWorksheet("Data");
|
|
148
|
+
|
|
149
|
+
// Write rows one at a time
|
|
150
|
+
for (let i = 0; i < 1000000; i++) {
|
|
151
|
+
sheet.addRow([`Row ${i}`, i, new Date()]).commit();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Commit worksheet and finalize
|
|
155
|
+
sheet.commit();
|
|
156
|
+
await workbook.commit();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## CSV Support
|
|
160
|
+
|
|
161
|
+
### Node.js (Full Streaming Support)
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { Workbook } from "@cj-tech-master/excelts";
|
|
165
|
+
|
|
166
|
+
const workbook = new Workbook();
|
|
167
|
+
|
|
168
|
+
// Read CSV from file (streaming)
|
|
169
|
+
await workbook.csv.readFile("data.csv");
|
|
170
|
+
|
|
171
|
+
// Read CSV from stream
|
|
172
|
+
import fs from "fs";
|
|
173
|
+
const stream = fs.createReadStream("data.csv");
|
|
174
|
+
await workbook.csv.read(stream, { sheetName: "Imported" });
|
|
175
|
+
|
|
176
|
+
// Write CSV to file (streaming)
|
|
177
|
+
await workbook.csv.writeFile("output.csv");
|
|
178
|
+
|
|
179
|
+
// Write CSV to stream
|
|
180
|
+
const writeStream = fs.createWriteStream("output.csv");
|
|
181
|
+
await workbook.csv.write(writeStream);
|
|
182
|
+
|
|
183
|
+
// Write CSV to buffer
|
|
184
|
+
const buffer = await workbook.csv.writeBuffer();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Browser (In-Memory)
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
import { Workbook } from "@cj-tech-master/excelts";
|
|
191
|
+
|
|
192
|
+
const workbook = new Workbook();
|
|
193
|
+
|
|
194
|
+
// Load CSV from string
|
|
195
|
+
workbook.csv.load(csvString);
|
|
196
|
+
|
|
197
|
+
// Load CSV from ArrayBuffer (e.g., from fetch or file input)
|
|
198
|
+
const response = await fetch("data.csv");
|
|
199
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
200
|
+
workbook.csv.load(arrayBuffer);
|
|
201
|
+
|
|
202
|
+
// Write CSV to string
|
|
203
|
+
const csvOutput = workbook.csv.writeString();
|
|
204
|
+
|
|
205
|
+
// Write CSV to Uint8Array buffer
|
|
206
|
+
const buffer = workbook.csv.writeBuffer();
|
|
207
|
+
```
|
|
208
|
+
|
|
107
209
|
## Browser Support
|
|
108
210
|
|
|
109
211
|
ExcelTS has native browser support with **zero configuration** required for modern bundlers.
|
|
@@ -152,8 +254,7 @@ const url = URL.createObjectURL(blob);
|
|
|
152
254
|
|
|
153
255
|
### Node.js
|
|
154
256
|
|
|
155
|
-
- **Node.js >=
|
|
156
|
-
- Recommended: Node.js >= 20.0.0 for best performance
|
|
257
|
+
- **Node.js >= 20.0.0** (ES2020 native support)
|
|
157
258
|
|
|
158
259
|
### Browsers (No Polyfills Required)
|
|
159
260
|
|
|
@@ -243,9 +344,9 @@ This project is a fork of ExcelJS with modernization improvements. All credit fo
|
|
|
243
344
|
|
|
244
345
|
## Links
|
|
245
346
|
|
|
246
|
-
- [GitHub Repository](https://github.com/cjnoname/
|
|
347
|
+
- [GitHub Repository](https://github.com/cjnoname/excelts)
|
|
247
348
|
- [Original ExcelJS](https://github.com/exceljs/exceljs)
|
|
248
|
-
- [Issue Tracker](https://github.com/cjnoname/
|
|
349
|
+
- [Issue Tracker](https://github.com/cjnoname/excelts/issues)
|
|
249
350
|
|
|
250
351
|
## Changelog
|
|
251
352
|
|
package/README_zh.md
CHANGED
|
@@ -104,6 +104,108 @@ cell.fill = {
|
|
|
104
104
|
- 数据保护
|
|
105
105
|
- 注释和批注
|
|
106
106
|
|
|
107
|
+
## 流式 API(Node.js)
|
|
108
|
+
|
|
109
|
+
处理大型 Excel 文件时无需将整个文件加载到内存中,ExcelTS 提供了流式读写 API。
|
|
110
|
+
|
|
111
|
+
### 流式读取器
|
|
112
|
+
|
|
113
|
+
以最小内存占用读取大型 XLSX 文件:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import { WorkbookReader } from "@cj-tech-master/excelts";
|
|
117
|
+
|
|
118
|
+
// 从文件路径读取
|
|
119
|
+
const reader = new WorkbookReader("large-file.xlsx", {
|
|
120
|
+
worksheets: "emit", // 触发工作表事件
|
|
121
|
+
sharedStrings: "cache", // 缓存共享字符串以获取单元格值
|
|
122
|
+
hyperlinks: "ignore", // 忽略超链接
|
|
123
|
+
styles: "ignore" // 忽略样式以加快解析
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
for await (const worksheet of reader) {
|
|
127
|
+
console.log(`正在读取: ${worksheet.name}`);
|
|
128
|
+
for await (const row of worksheet) {
|
|
129
|
+
console.log(row.values);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 流式写入器
|
|
135
|
+
|
|
136
|
+
逐行写入大型 XLSX 文件:
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
import { WorkbookWriter } from "@cj-tech-master/excelts";
|
|
140
|
+
|
|
141
|
+
const workbook = new WorkbookWriter({
|
|
142
|
+
filename: "output.xlsx",
|
|
143
|
+
useSharedStrings: true,
|
|
144
|
+
useStyles: true
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const sheet = workbook.addWorksheet("Data");
|
|
148
|
+
|
|
149
|
+
// 逐行写入
|
|
150
|
+
for (let i = 0; i < 1000000; i++) {
|
|
151
|
+
sheet.addRow([`第 ${i} 行`, i, new Date()]).commit();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 提交工作表并完成
|
|
155
|
+
sheet.commit();
|
|
156
|
+
await workbook.commit();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## CSV 支持
|
|
160
|
+
|
|
161
|
+
### Node.js(完整流式支持)
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { Workbook } from "@cj-tech-master/excelts";
|
|
165
|
+
|
|
166
|
+
const workbook = new Workbook();
|
|
167
|
+
|
|
168
|
+
// 从文件读取 CSV(流式)
|
|
169
|
+
await workbook.csv.readFile("data.csv");
|
|
170
|
+
|
|
171
|
+
// 从流读取 CSV
|
|
172
|
+
import fs from "fs";
|
|
173
|
+
const stream = fs.createReadStream("data.csv");
|
|
174
|
+
await workbook.csv.read(stream, { sheetName: "Imported" });
|
|
175
|
+
|
|
176
|
+
// 写入 CSV 到文件(流式)
|
|
177
|
+
await workbook.csv.writeFile("output.csv");
|
|
178
|
+
|
|
179
|
+
// 写入 CSV 到流
|
|
180
|
+
const writeStream = fs.createWriteStream("output.csv");
|
|
181
|
+
await workbook.csv.write(writeStream);
|
|
182
|
+
|
|
183
|
+
// 写入 CSV 到 buffer
|
|
184
|
+
const buffer = await workbook.csv.writeBuffer();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 浏览器(内存中)
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
import { Workbook } from "@cj-tech-master/excelts";
|
|
191
|
+
|
|
192
|
+
const workbook = new Workbook();
|
|
193
|
+
|
|
194
|
+
// 从字符串加载 CSV
|
|
195
|
+
workbook.csv.load(csvString);
|
|
196
|
+
|
|
197
|
+
// 从 ArrayBuffer 加载 CSV(例如从 fetch 或文件输入)
|
|
198
|
+
const response = await fetch("data.csv");
|
|
199
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
200
|
+
workbook.csv.load(arrayBuffer);
|
|
201
|
+
|
|
202
|
+
// 写入 CSV 为字符串
|
|
203
|
+
const csvOutput = workbook.csv.writeString();
|
|
204
|
+
|
|
205
|
+
// 写入 CSV 为 Uint8Array buffer
|
|
206
|
+
const buffer = workbook.csv.writeBuffer();
|
|
207
|
+
```
|
|
208
|
+
|
|
107
209
|
## 浏览器支持
|
|
108
210
|
|
|
109
211
|
ExcelTS 原生支持浏览器环境,现代打包工具**无需任何配置**。
|
|
@@ -152,8 +254,7 @@ const url = URL.createObjectURL(blob);
|
|
|
152
254
|
|
|
153
255
|
### Node.js
|
|
154
256
|
|
|
155
|
-
- **Node.js >=
|
|
156
|
-
- 推荐:Node.js >= 20.0.0 以获得最佳性能
|
|
257
|
+
- **Node.js >= 20.0.0**(原生支持 ES2020)
|
|
157
258
|
|
|
158
259
|
### 浏览器(无需 Polyfills)
|
|
159
260
|
|
|
@@ -243,9 +344,9 @@ MIT License
|
|
|
243
344
|
|
|
244
345
|
## 链接
|
|
245
346
|
|
|
246
|
-
- [GitHub 仓库](https://github.com/cjnoname/
|
|
347
|
+
- [GitHub 仓库](https://github.com/cjnoname/excelts)
|
|
247
348
|
- [原始 ExcelJS](https://github.com/exceljs/exceljs)
|
|
248
|
-
- [问题跟踪](https://github.com/cjnoname/
|
|
349
|
+
- [问题跟踪](https://github.com/cjnoname/excelts/issues)
|
|
249
350
|
|
|
250
351
|
## 更新日志
|
|
251
352
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cj-tech-master/excelts",
|
|
3
|
-
"version": "1.6.3-canary.
|
|
3
|
+
"version": "1.6.3-canary.20251224125850.7da664f",
|
|
4
4
|
"description": "TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"type": "module",
|
|
30
30
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
31
|
+
"node": ">=20.0.0"
|
|
32
32
|
},
|
|
33
33
|
"browserslist": [
|
|
34
34
|
"chrome >= 85",
|