@cj-tech-master/excelts 7.6.0 → 8.0.0
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 +99 -577
- package/README_zh.md +101 -577
- package/dist/browser/index.browser.d.ts +3 -0
- package/dist/browser/index.browser.js +2 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/modules/archive/compression/compress.browser.js +4 -4
- package/dist/browser/modules/archive/compression/deflate-fallback.d.ts +24 -22
- package/dist/browser/modules/archive/compression/deflate-fallback.js +664 -360
- package/dist/browser/modules/archive/compression/streaming-compress.browser.d.ts +7 -0
- package/dist/browser/modules/archive/compression/streaming-compress.browser.js +15 -3
- package/dist/browser/modules/archive/compression/streaming-compress.d.ts +5 -0
- package/dist/browser/modules/archive/compression/streaming-compress.js +7 -0
- package/dist/browser/modules/archive/zip/stream.js +27 -3
- package/dist/browser/modules/excel/workbook.browser.d.ts +72 -0
- package/dist/browser/modules/excel/workbook.browser.js +226 -0
- package/dist/browser/modules/excel/workbook.d.ts +32 -1
- package/dist/browser/modules/excel/workbook.js +47 -2
- package/dist/browser/modules/excel/xlsx/xlsx.browser.js +42 -4
- package/dist/browser/modules/markdown/constants.d.ts +30 -0
- package/dist/browser/modules/markdown/constants.js +30 -0
- package/dist/browser/modules/markdown/errors.d.ts +21 -0
- package/dist/browser/modules/markdown/errors.js +23 -0
- package/dist/browser/modules/markdown/format/index.d.ts +54 -0
- package/dist/browser/modules/markdown/format/index.js +307 -0
- package/dist/browser/modules/markdown/index.d.ts +15 -0
- package/dist/browser/modules/markdown/index.js +22 -0
- package/dist/browser/modules/markdown/parse/index.d.ts +70 -0
- package/dist/browser/modules/markdown/parse/index.js +428 -0
- package/dist/browser/modules/markdown/types.d.ts +130 -0
- package/dist/browser/modules/markdown/types.js +6 -0
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/modules/archive/compression/compress.browser.js +4 -4
- package/dist/cjs/modules/archive/compression/deflate-fallback.js +664 -360
- package/dist/cjs/modules/archive/compression/streaming-compress.browser.js +15 -2
- package/dist/cjs/modules/archive/compression/streaming-compress.js +8 -0
- package/dist/cjs/modules/archive/zip/stream.js +26 -2
- package/dist/cjs/modules/excel/workbook.browser.js +226 -0
- package/dist/cjs/modules/excel/workbook.js +46 -1
- package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +42 -4
- package/dist/cjs/modules/markdown/constants.js +33 -0
- package/dist/cjs/modules/markdown/errors.js +28 -0
- package/dist/cjs/modules/markdown/format/index.js +310 -0
- package/dist/cjs/modules/markdown/index.js +30 -0
- package/dist/cjs/modules/markdown/parse/index.js +432 -0
- package/dist/cjs/modules/markdown/types.js +7 -0
- package/dist/esm/index.browser.js +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/modules/archive/compression/compress.browser.js +4 -4
- package/dist/esm/modules/archive/compression/deflate-fallback.js +664 -360
- package/dist/esm/modules/archive/compression/streaming-compress.browser.js +15 -3
- package/dist/esm/modules/archive/compression/streaming-compress.js +7 -0
- package/dist/esm/modules/archive/zip/stream.js +27 -3
- package/dist/esm/modules/excel/workbook.browser.js +226 -0
- package/dist/esm/modules/excel/workbook.js +47 -2
- package/dist/esm/modules/excel/xlsx/xlsx.browser.js +42 -4
- package/dist/esm/modules/markdown/constants.js +30 -0
- package/dist/esm/modules/markdown/errors.js +23 -0
- package/dist/esm/modules/markdown/format/index.js +307 -0
- package/dist/esm/modules/markdown/index.js +22 -0
- package/dist/esm/modules/markdown/parse/index.js +428 -0
- package/dist/esm/modules/markdown/types.js +6 -0
- package/dist/iife/excelts.iife.js +1342 -283
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +38 -34
- package/dist/types/index.browser.d.ts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/modules/archive/compression/deflate-fallback.d.ts +24 -22
- package/dist/types/modules/archive/compression/streaming-compress.browser.d.ts +7 -0
- package/dist/types/modules/archive/compression/streaming-compress.d.ts +5 -0
- package/dist/types/modules/excel/workbook.browser.d.ts +72 -0
- package/dist/types/modules/excel/workbook.d.ts +32 -1
- package/dist/types/modules/markdown/constants.d.ts +30 -0
- package/dist/types/modules/markdown/errors.d.ts +21 -0
- package/dist/types/modules/markdown/format/index.d.ts +54 -0
- package/dist/types/modules/markdown/index.d.ts +15 -0
- package/dist/types/modules/markdown/parse/index.d.ts +70 -0
- package/dist/types/modules/markdown/types.d.ts +130 -0
- package/package.json +56 -32
package/README.md
CHANGED
|
@@ -1,650 +1,172 @@
|
|
|
1
1
|
# ExcelTS
|
|
2
2
|
|
|
3
|
-
[](https://github.com/cjnoname/excelts/actions/workflows/ci.yml)
|
|
3
|
+
[](https://github.com/cjnoname/excelts/actions/workflows/ci.yml) [中文](README_zh.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Zero-dependency, AI-friendly TypeScript toolkit — Excel, PDF, CSV, Markdown, XML, ZIP, and streaming in one library with seven standalone modules.
|
|
6
6
|
|
|
7
7
|
## About This Project
|
|
8
8
|
|
|
9
9
|
ExcelTS is a zero-dependency TypeScript toolkit for spreadsheets and documents:
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
11
|
+
- **AI-Friendly** — Clean, consistent API designed for AI coding agents. Every module has comprehensive documentation and runnable examples for AI to learn from
|
|
12
|
+
- **Zero Runtime Dependencies** — Pure TypeScript, no external packages
|
|
13
|
+
- **Seven Modules** — Excel, PDF, CSV, Markdown, XML, Archive, Stream
|
|
14
|
+
- **Cross-Platform** — Node.js 22+, Bun, Chrome 89+, Firefox 102+, Safari 14.1+
|
|
15
|
+
- **ESM First** — Native ES Modules with CommonJS compatibility and full tree-shaking
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Modules
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
- [PDF Module](src/modules/pdf/README.md) — Full-featured zero-dependency PDF engine with encryption and font embedding
|
|
21
|
-
- [CSV Module](src/modules/csv/README.md) — RFC 4180 parser/formatter, streaming, data generation
|
|
22
|
-
- [Archive Module](src/modules/archive/README.md) — ZIP/TAR create/read/edit, compression, encryption
|
|
23
|
-
- [Stream Module](src/modules/stream/README.md) — Cross-platform Readable/Writable/Transform/Duplex
|
|
19
|
+
ExcelTS is organized into seven standalone modules. Each module has its own documentation and runnable examples.
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
### Excel — XLSX/JSON Workbook Manager
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
Create, read, and modify Excel spreadsheets with full styling, formulas, images, and streaming support.
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install @cj-tech-master/excelts
|
|
33
|
-
```
|
|
25
|
+
- [Documentation](src/modules/excel/README.md) | [中文](src/modules/excel/README_zh.md)
|
|
26
|
+
- [Examples](src/modules/excel/examples/)
|
|
34
27
|
|
|
35
|
-
|
|
28
|
+
### PDF — Zero-Dependency PDF Engine
|
|
36
29
|
|
|
37
|
-
|
|
30
|
+
Full-featured PDF generation with font embedding, encryption, images, and Excel-to-PDF conversion.
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
- [Documentation](src/modules/pdf/README.md) | [中文](src/modules/pdf/README_zh.md)
|
|
33
|
+
- [Examples](src/modules/pdf/examples/)
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
const sheet = workbook.addWorksheet("My Sheet");
|
|
35
|
+
### CSV — RFC 4180 Parser/Formatter
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
sheet.addRow(["Name", "Age", "Email"]);
|
|
47
|
-
sheet.addRow(["John Doe", 30, "john@example.com"]);
|
|
48
|
-
sheet.addRow(["Jane Smith", 25, "jane@example.com"]);
|
|
49
|
-
|
|
50
|
-
// Save to file
|
|
51
|
-
// Node.js only: write to a file path
|
|
52
|
-
await workbook.xlsx.writeFile("output.xlsx");
|
|
37
|
+
High-performance CSV parsing and formatting with streaming, dynamic typing, data generation, and worker pool support.
|
|
53
38
|
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
- [Documentation](src/modules/csv/README.md) | [中文](src/modules/csv/README_zh.md)
|
|
40
|
+
- [Examples](src/modules/csv/examples/)
|
|
56
41
|
|
|
57
|
-
###
|
|
42
|
+
### Markdown — GFM Table Parser/Formatter
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
import { Workbook } from "@cj-tech-master/excelts";
|
|
44
|
+
Parse and format GitHub Flavored Markdown tables with alignment round-trip and Workbook integration.
|
|
61
45
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
await workbook.xlsx.readFile("input.xlsx");
|
|
46
|
+
- [Documentation](src/modules/markdown/README.md) | [中文](src/modules/markdown/README_zh.md)
|
|
47
|
+
- [Examples](src/modules/markdown/examples/)
|
|
65
48
|
|
|
66
|
-
|
|
49
|
+
### XML — SAX/DOM Parser, Query Engine, Writer
|
|
67
50
|
|
|
68
|
-
|
|
69
|
-
worksheet.eachRow((row, rowNumber) => {
|
|
70
|
-
console.log("Row " + rowNumber + " = " + JSON.stringify(row.values));
|
|
71
|
-
});
|
|
72
|
-
```
|
|
51
|
+
Streaming and buffered XML processing with query engine, namespace support, and dual-mode writing.
|
|
73
52
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```javascript
|
|
77
|
-
// Set cell value and style
|
|
78
|
-
const cell = worksheet.getCell("A1");
|
|
79
|
-
cell.value = "Hello";
|
|
80
|
-
cell.font = {
|
|
81
|
-
name: "Arial",
|
|
82
|
-
size: 16,
|
|
83
|
-
bold: true,
|
|
84
|
-
color: { argb: "FFFF0000" }
|
|
85
|
-
};
|
|
86
|
-
cell.fill = {
|
|
87
|
-
type: "pattern",
|
|
88
|
-
pattern: "solid",
|
|
89
|
-
fgColor: { argb: "FFFFFF00" }
|
|
90
|
-
};
|
|
91
|
-
```
|
|
53
|
+
- [Documentation](src/modules/xml/README.md) | [中文](src/modules/xml/README_zh.md)
|
|
54
|
+
- [Examples](src/modules/xml/examples/)
|
|
92
55
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
- **Excel Operations**
|
|
96
|
-
- Create, read, and modify XLSX files
|
|
97
|
-
- Multiple worksheet support
|
|
98
|
-
- Cell styling (fonts, colors, borders, fills)
|
|
99
|
-
- Cell merging and formatting
|
|
100
|
-
- Row and column properties
|
|
101
|
-
- Freeze panes and split views
|
|
102
|
-
|
|
103
|
-
- **Data Handling**
|
|
104
|
-
- Rich text support
|
|
105
|
-
- Formulas and calculated values
|
|
106
|
-
- Data validation
|
|
107
|
-
- Conditional formatting
|
|
108
|
-
- Images and charts
|
|
109
|
-
- Hyperlinks
|
|
110
|
-
- Pivot tables
|
|
111
|
-
|
|
112
|
-
- **PDF Export**
|
|
113
|
-
- Full-featured, zero-dependency PDF engine (standalone or with Excel)
|
|
114
|
-
- Full cell styling (fonts, colors, borders, fills, alignment)
|
|
115
|
-
- Automatic pagination with repeat header rows
|
|
116
|
-
- TrueType font embedding for Unicode/CJK text
|
|
117
|
-
- JPEG and PNG image embedding with transparency
|
|
118
|
-
- Password protection and encryption
|
|
119
|
-
- Per-worksheet page setup (size, orientation, margins)
|
|
120
|
-
- Tree-shakeable (not imported = not bundled)
|
|
121
|
-
|
|
122
|
-
- **Advanced Features**
|
|
123
|
-
- Streaming for large files
|
|
124
|
-
- CSV import/export
|
|
125
|
-
- Tables with auto-filters
|
|
126
|
-
- Page setup and printing options
|
|
127
|
-
- Data protection
|
|
128
|
-
- Comments and notes
|
|
56
|
+
### Archive — ZIP/TAR Create/Read/Edit
|
|
129
57
|
|
|
130
|
-
|
|
58
|
+
ZIP and TAR archive creation, reading, editing, streaming, encryption, and compression utilities.
|
|
131
59
|
|
|
132
|
-
|
|
60
|
+
- [Documentation](src/modules/archive/README.md) | [中文](src/modules/archive/README_zh.md)
|
|
61
|
+
- [Examples](src/modules/archive/examples/)
|
|
133
62
|
|
|
134
|
-
|
|
135
|
-
// Main entry - Excel core (Workbook, Worksheet, Cell, etc.)
|
|
136
|
-
import { Workbook, WorkbookWriter } from "@cj-tech-master/excelts";
|
|
63
|
+
### Stream — Cross-Platform Streaming
|
|
137
64
|
|
|
138
|
-
|
|
139
|
-
import { SaxParser, parseXml, XmlWriter, query } from "@cj-tech-master/excelts/xml";
|
|
65
|
+
Node.js-compatible Readable/Writable/Transform/Duplex that works identically in Node.js and browsers.
|
|
140
66
|
|
|
141
|
-
|
|
142
|
-
|
|
67
|
+
- [Documentation](src/modules/stream/README.md) | [中文](src/modules/stream/README_zh.md)
|
|
68
|
+
- [Examples](src/modules/stream/examples/)
|
|
143
69
|
|
|
144
|
-
|
|
145
|
-
import { parseCsv, formatCsv, CsvParserStream } from "@cj-tech-master/excelts/csv";
|
|
70
|
+
## Installation
|
|
146
71
|
|
|
147
|
-
|
|
148
|
-
|
|
72
|
+
```bash
|
|
73
|
+
npm install @cj-tech-master/excelts
|
|
149
74
|
```
|
|
150
75
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
## PDF Export
|
|
154
|
-
|
|
155
|
-
Export any workbook to PDF with zero external dependencies:
|
|
156
|
-
|
|
157
|
-
```javascript
|
|
158
|
-
import { Workbook, excelToPdf } from "@cj-tech-master/excelts";
|
|
159
|
-
|
|
160
|
-
const workbook = new Workbook();
|
|
161
|
-
const sheet = workbook.addWorksheet("Report");
|
|
162
|
-
sheet.columns = [
|
|
163
|
-
{ header: "Product", key: "product", width: 20 },
|
|
164
|
-
{ header: "Revenue", key: "revenue", width: 15 }
|
|
165
|
-
];
|
|
166
|
-
sheet.addRow({ product: "Widget", revenue: 1000 });
|
|
167
|
-
sheet.getColumn("revenue").numFmt = "$#,##0.00";
|
|
168
|
-
|
|
169
|
-
// One-line export
|
|
170
|
-
const pdf = excelToPdf(workbook, {
|
|
171
|
-
showGridLines: true,
|
|
172
|
-
showPageNumbers: true,
|
|
173
|
-
title: "Sales Report"
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// Node.js: write to file
|
|
177
|
-
import { writeFileSync } from "fs";
|
|
178
|
-
writeFileSync("report.pdf", pdf);
|
|
179
|
-
|
|
180
|
-
// Browser: download
|
|
181
|
-
const blob = new Blob([pdf], { type: "application/pdf" });
|
|
182
|
-
const url = URL.createObjectURL(blob);
|
|
183
|
-
window.open(url);
|
|
184
|
-
```
|
|
76
|
+
## Quick Start
|
|
185
77
|
|
|
186
|
-
|
|
78
|
+
```typescript
|
|
79
|
+
import { Workbook } from "@cj-tech-master/excelts";
|
|
187
80
|
|
|
188
|
-
|
|
81
|
+
// Create
|
|
189
82
|
const workbook = new Workbook();
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
### Encryption
|
|
195
|
-
|
|
196
|
-
```javascript
|
|
197
|
-
const pdf = excelToPdf(workbook, {
|
|
198
|
-
encryption: {
|
|
199
|
-
ownerPassword: "admin",
|
|
200
|
-
userPassword: "reader",
|
|
201
|
-
permissions: { print: true, copy: false }
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### Unicode / CJK
|
|
207
|
-
|
|
208
|
-
```javascript
|
|
209
|
-
import { readFileSync } from "fs";
|
|
83
|
+
const sheet = workbook.addWorksheet("Sheet1");
|
|
84
|
+
sheet.addRow(["Name", "Age"]);
|
|
85
|
+
sheet.addRow(["Alice", 30]);
|
|
86
|
+
await workbook.xlsx.writeFile("output.xlsx");
|
|
210
87
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
88
|
+
// Read
|
|
89
|
+
const wb = new Workbook();
|
|
90
|
+
await wb.xlsx.readFile("output.xlsx");
|
|
91
|
+
wb.getWorksheet(1).eachRow((row, n) => console.log(n, row.values));
|
|
214
92
|
```
|
|
215
93
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
Generate PDFs from plain data — no workbook, no Map objects, no boilerplate:
|
|
219
|
-
|
|
220
|
-
```javascript
|
|
94
|
+
```typescript
|
|
95
|
+
// PDF — generate from data, no Workbook needed
|
|
221
96
|
import { pdf } from "@cj-tech-master/excelts/pdf";
|
|
222
|
-
|
|
223
|
-
// Simplest — pass a 2D array
|
|
224
|
-
const bytes = pdf([
|
|
97
|
+
const pdfBytes = pdf([
|
|
225
98
|
["Product", "Revenue"],
|
|
226
|
-
["Widget", 1000]
|
|
227
|
-
["Gadget", 2500]
|
|
99
|
+
["Widget", 1000]
|
|
228
100
|
]);
|
|
229
101
|
|
|
230
|
-
//
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
columns: [
|
|
235
|
-
{ width: 25, header: "Product" },
|
|
236
|
-
{ width: 15, header: "Revenue" }
|
|
237
|
-
],
|
|
238
|
-
data: [
|
|
239
|
-
["Widget", 1000],
|
|
240
|
-
["Gadget", 2500]
|
|
241
|
-
]
|
|
242
|
-
},
|
|
243
|
-
{ showGridLines: true }
|
|
244
|
-
);
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
For the full API reference and all options, see the [PDF Module documentation](src/modules/pdf/README.md).
|
|
102
|
+
// CSV — parse and format
|
|
103
|
+
import { parseCsv, formatCsv } from "@cj-tech-master/excelts/csv";
|
|
104
|
+
const rows = parseCsv("name,age\nAlice,30", { headers: true });
|
|
105
|
+
const csv = formatCsv([{ name: "Bob", age: 25 }], { headers: true });
|
|
248
106
|
|
|
249
|
-
|
|
107
|
+
// XML — parse, query, write
|
|
108
|
+
import { parseXml, queryAll, XmlWriter } from "@cj-tech-master/excelts/xml";
|
|
109
|
+
const titles = queryAll(parseXml(xmlString).root, "book/title");
|
|
250
110
|
|
|
251
|
-
|
|
252
|
-
|
|
111
|
+
// ZIP — create and extract
|
|
112
|
+
import { zip, unzip } from "@cj-tech-master/excelts/zip";
|
|
113
|
+
const archive = await zip().add("hello.txt", "Hello!").bytes();
|
|
253
114
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
When a non-UTF-8 encoding is used, Unicode extra fields can be emitted for better
|
|
259
|
-
cross-tool compatibility.
|
|
260
|
-
|
|
261
|
-
## XML Toolkit
|
|
262
|
-
|
|
263
|
-
ExcelTS includes a standalone, zero-dependency XML module with streaming and buffered parsing/writing. It powers the XLSX pipeline internally and is available as a standalone subpath export.
|
|
264
|
-
|
|
265
|
-
### Key Features
|
|
115
|
+
// Markdown — parse and format tables
|
|
116
|
+
import { parseMarkdown, formatMarkdown } from "@cj-tech-master/excelts/markdown";
|
|
117
|
+
const table = parseMarkdown("| A | B |\n|---|---|\n| 1 | 2 |");
|
|
118
|
+
```
|
|
266
119
|
|
|
267
|
-
|
|
268
|
-
- **DOM Parser** — Build a queryable XML tree from a string
|
|
269
|
-
- **Query Engine** — Simplified path expressions (`a/b[@id='1']`, `a//c`, `a/b[0]`)
|
|
270
|
-
- **Dual-Mode Writer** — Buffered (`XmlWriter`) and streaming (`XmlStreamWriter`)
|
|
271
|
-
- **Full Namespace Support** — Prefix resolution, reserved namespace enforcement, unbound prefix detection
|
|
272
|
-
- **Security Hardened** — Entity expansion limits, nesting depth limits, duplicate attribute rejection, BOM handling
|
|
120
|
+
## Subpath Exports
|
|
273
121
|
|
|
274
|
-
|
|
122
|
+
Each module is available as a standalone subpath export:
|
|
275
123
|
|
|
276
124
|
```typescript
|
|
125
|
+
import { Workbook, WorkbookWriter } from "@cj-tech-master/excelts";
|
|
277
126
|
import { SaxParser, parseXml, XmlWriter, query } from "@cj-tech-master/excelts/xml";
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
parser.write('<root><item id="1">hello</item></root>');
|
|
283
|
-
parser.close();
|
|
284
|
-
|
|
285
|
-
// DOM parse + query
|
|
286
|
-
const doc = parseXml("<root><a><b>1</b><b>2</b></a></root>");
|
|
287
|
-
const items = queryAll(doc.root, "a/b"); // all <b> elements
|
|
288
|
-
|
|
289
|
-
// Write XML
|
|
290
|
-
const w = new XmlWriter();
|
|
291
|
-
w.openXml();
|
|
292
|
-
w.openNode("root");
|
|
293
|
-
w.leafNode("item", { id: "1" }, "hello");
|
|
294
|
-
w.closeNode();
|
|
295
|
-
console.log(w.xml);
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
For the full API reference, see the [XML Module documentation](src/modules/xml/README.md).
|
|
299
|
-
|
|
300
|
-
### Editing an existing ZIP (ZipEditor)
|
|
301
|
-
|
|
302
|
-
ExcelTS also includes a ZIP editor that can apply filesystem-like edits to an existing archive
|
|
303
|
-
and then output a new ZIP.
|
|
304
|
-
|
|
305
|
-
- Supports `set()`, `delete()`, `rename()`, `deleteDirectory()`, `setComment()`
|
|
306
|
-
- Unchanged entries are passed through efficiently when possible
|
|
307
|
-
|
|
308
|
-
```js
|
|
309
|
-
import { editZip } from "@cj-tech-master/excelts";
|
|
310
|
-
|
|
311
|
-
const editor = await editZip(existingZipBytes, {
|
|
312
|
-
reproducible: true,
|
|
313
|
-
|
|
314
|
-
// Passthrough behavior for unchanged entries:
|
|
315
|
-
// - "strict" (default): raw passthrough must be available or it throws
|
|
316
|
-
// - "best-effort": if raw passthrough is unavailable, fall back to extract+re-add
|
|
317
|
-
preserve: "best-effort",
|
|
318
|
-
onWarning: w => console.warn(w.code, w.entry, w.message)
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
editor.delete("old.txt");
|
|
322
|
-
editor.rename("a.txt", "renamed.txt");
|
|
323
|
-
editor.set("new.txt", "hello");
|
|
324
|
-
|
|
325
|
-
const out = await editor.bytes();
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
## Streaming API
|
|
329
|
-
|
|
330
|
-
For processing large Excel files without loading them entirely into memory, ExcelTS provides streaming reader and writer APIs.
|
|
331
|
-
|
|
332
|
-
- **Node.js**: `WorkbookReader` supports reading from a file path, and `WorkbookWriter` supports writing to a filename.
|
|
333
|
-
- **Browsers**: use `Uint8Array` / `ArrayBuffer` / Web `ReadableStream<Uint8Array>` for reading, and Web `WritableStream<Uint8Array>` for writing.
|
|
334
|
-
- Note: ExcelTS does not re-export the internal stream utility surface (e.g. `Readable`, `Writable`). Prefer standard Web Streams (browser/Node 22+) or Node.js streams.
|
|
335
|
-
|
|
336
|
-
### Streaming Reader
|
|
337
|
-
|
|
338
|
-
Read large XLSX files with minimal memory usage:
|
|
339
|
-
|
|
340
|
-
```javascript
|
|
341
|
-
import { WorkbookReader } from "@cj-tech-master/excelts";
|
|
342
|
-
|
|
343
|
-
// Node.js: read from file path
|
|
344
|
-
const reader = new WorkbookReader("large-file.xlsx", {
|
|
345
|
-
worksheets: "emit", // emit worksheet events
|
|
346
|
-
sharedStrings: "cache", // cache shared strings for cell values
|
|
347
|
-
hyperlinks: "ignore", // ignore hyperlinks
|
|
348
|
-
styles: "ignore" // ignore styles for faster parsing
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
for await (const worksheet of reader) {
|
|
352
|
-
console.log(`Reading: ${worksheet.name}`);
|
|
353
|
-
for await (const row of worksheet) {
|
|
354
|
-
console.log(row.values);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
### Streaming Writer
|
|
360
|
-
|
|
361
|
-
Write large XLSX files row by row:
|
|
362
|
-
|
|
363
|
-
```javascript
|
|
364
|
-
import { WorkbookWriter } from "@cj-tech-master/excelts";
|
|
365
|
-
|
|
366
|
-
// Node.js: write to filename
|
|
367
|
-
const workbook = new WorkbookWriter({
|
|
368
|
-
filename: "output.xlsx",
|
|
369
|
-
useSharedStrings: true,
|
|
370
|
-
useStyles: true
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
const sheet = workbook.addWorksheet("Data");
|
|
374
|
-
|
|
375
|
-
// Write rows one at a time
|
|
376
|
-
for (let i = 0; i < 1000000; i++) {
|
|
377
|
-
sheet.addRow([`Row ${i}`, i, new Date()]).commit();
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Commit worksheet and finalize
|
|
381
|
-
sheet.commit();
|
|
382
|
-
await workbook.commit();
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
### Web Streams (Node.js 22+ and Browsers)
|
|
386
|
-
|
|
387
|
-
`WorkbookWriter` can write to a Web `WritableStream<Uint8Array>`, and `WorkbookReader` can read from a Web `ReadableStream<Uint8Array>`.
|
|
388
|
-
|
|
389
|
-
This does **not** require importing any extra stream utility surface from ExcelTS; it uses the standard Web Streams API.
|
|
390
|
-
|
|
391
|
-
- Full runnable example: [src/modules/excel/examples/web-streams-reader-writer.ts](src/modules/excel/examples/web-streams-reader-writer.ts)
|
|
392
|
-
|
|
393
|
-
Run locally (Node.js 22+):
|
|
394
|
-
|
|
395
|
-
```bash
|
|
396
|
-
npx tsx src/modules/excel/examples/web-streams-reader-writer.ts
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
Minimal end-to-end snippet:
|
|
400
|
-
|
|
401
|
-
```javascript
|
|
402
|
-
import { WorkbookWriter, WorkbookReader } from "@cj-tech-master/excelts";
|
|
403
|
-
|
|
404
|
-
// 1) Write workbook -> Web WritableStream
|
|
405
|
-
const chunks = [];
|
|
406
|
-
const writable = new WritableStream({
|
|
407
|
-
write(chunk) {
|
|
408
|
-
chunks.push(chunk);
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
const writer = new WorkbookWriter({ stream: writable });
|
|
413
|
-
const sheet = writer.addWorksheet("Sheet1");
|
|
414
|
-
sheet.addRow(["Name", "Score"]).commit();
|
|
415
|
-
sheet.addRow(["Alice", 98]).commit();
|
|
416
|
-
await sheet.commit();
|
|
417
|
-
await writer.commit();
|
|
418
|
-
|
|
419
|
-
// 2) Read workbook <- Web ReadableStream
|
|
420
|
-
const bytes = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));
|
|
421
|
-
let offset = 0;
|
|
422
|
-
for (const c of chunks) {
|
|
423
|
-
bytes.set(c, offset);
|
|
424
|
-
offset += c.length;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
const readable = new ReadableStream({
|
|
428
|
-
start(controller) {
|
|
429
|
-
controller.enqueue(bytes);
|
|
430
|
-
controller.close();
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
const reader = new WorkbookReader(readable, { worksheets: "emit" });
|
|
435
|
-
for await (const ws of reader) {
|
|
436
|
-
for await (const row of ws) {
|
|
437
|
-
console.log(row.values);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
## CSV Support
|
|
443
|
-
|
|
444
|
-
### Node.js (Full Streaming Support)
|
|
445
|
-
|
|
446
|
-
```javascript
|
|
447
|
-
import { Workbook } from "@cj-tech-master/excelts";
|
|
448
|
-
import fs from "fs";
|
|
449
|
-
|
|
450
|
-
const workbook = new Workbook();
|
|
451
|
-
|
|
452
|
-
// Read CSV from file
|
|
453
|
-
await workbook.readCsvFile("data.csv");
|
|
454
|
-
|
|
455
|
-
// Read CSV from stream
|
|
456
|
-
const stream = fs.createReadStream("data.csv");
|
|
457
|
-
await workbook.readCsv(stream, { sheetName: "Imported" });
|
|
458
|
-
|
|
459
|
-
// Write CSV to file
|
|
460
|
-
await workbook.writeCsvFile("output.csv");
|
|
461
|
-
|
|
462
|
-
// Write CSV to stream
|
|
463
|
-
const writeStream = fs.createWriteStream("output.csv");
|
|
464
|
-
await workbook.writeCsv(writeStream);
|
|
465
|
-
|
|
466
|
-
// Write CSV to string / bytes
|
|
467
|
-
const csvText = workbook.writeCsv();
|
|
468
|
-
const bytes = await workbook.writeCsvBuffer();
|
|
127
|
+
import { zip, unzip, ZipArchive, compress } from "@cj-tech-master/excelts/zip";
|
|
128
|
+
import { parseCsv, formatCsv, CsvParserStream } from "@cj-tech-master/excelts/csv";
|
|
129
|
+
import { parseMarkdown, formatMarkdown, parseMarkdownAll } from "@cj-tech-master/excelts/markdown";
|
|
130
|
+
import { Readable, pipeline, createTransform } from "@cj-tech-master/excelts/stream";
|
|
469
131
|
```
|
|
470
132
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
```javascript
|
|
474
|
-
import { Workbook } from "@cj-tech-master/excelts";
|
|
475
|
-
|
|
476
|
-
const workbook = new Workbook();
|
|
477
|
-
|
|
478
|
-
// Read CSV from string
|
|
479
|
-
await workbook.readCsv(csvString);
|
|
480
|
-
|
|
481
|
-
// Read CSV from ArrayBuffer (e.g., from fetch)
|
|
482
|
-
const response = await fetch("data.csv");
|
|
483
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
484
|
-
await workbook.readCsv(arrayBuffer);
|
|
485
|
-
|
|
486
|
-
// Read CSV from File (e.g., <input type="file">)
|
|
487
|
-
await workbook.readCsv(file);
|
|
488
|
-
|
|
489
|
-
// Write CSV to string
|
|
490
|
-
const csvOutput = workbook.writeCsv();
|
|
491
|
-
|
|
492
|
-
// Write CSV to Uint8Array bytes
|
|
493
|
-
const bytes = await workbook.writeCsvBuffer();
|
|
494
|
-
```
|
|
133
|
+
Each subpath supports `browser`, `import` (ESM), and `require` (CJS) conditions.
|
|
495
134
|
|
|
496
135
|
## Browser Support
|
|
497
136
|
|
|
498
|
-
ExcelTS has native browser support with **zero configuration**
|
|
499
|
-
|
|
500
|
-
### Using with Bundlers (Vite, Webpack, Rollup, esbuild)
|
|
137
|
+
ExcelTS has native browser support with **zero configuration** for modern bundlers.
|
|
501
138
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
```javascript
|
|
139
|
+
```typescript
|
|
140
|
+
// Bundlers (Vite, Webpack, Rollup, esbuild) — just import
|
|
505
141
|
import { Workbook } from "@cj-tech-master/excelts";
|
|
506
|
-
|
|
507
|
-
const workbook = new Workbook();
|
|
508
|
-
const sheet = workbook.addWorksheet("Sheet1");
|
|
509
|
-
sheet.getCell("A1").value = "Hello, Browser!";
|
|
510
|
-
|
|
511
|
-
// Write to buffer and download
|
|
512
|
-
const buffer = await workbook.xlsx.writeBuffer();
|
|
513
|
-
const blob = new Blob([buffer], {
|
|
514
|
-
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
515
|
-
});
|
|
516
|
-
const url = URL.createObjectURL(blob);
|
|
517
|
-
// ... trigger download
|
|
142
|
+
const buffer = await new Workbook().addWorksheet("S1").workbook.xlsx.writeBuffer();
|
|
518
143
|
```
|
|
519
144
|
|
|
520
|
-
### Using with Script Tags (No Bundler)
|
|
521
|
-
|
|
522
145
|
```html
|
|
146
|
+
<!-- Script tag (no bundler) -->
|
|
523
147
|
<script src="https://unpkg.com/@cj-tech-master/excelts/dist/iife/excelts.iife.min.js"></script>
|
|
524
|
-
<script>
|
|
525
|
-
const { Workbook } = ExcelTS;
|
|
526
|
-
const wb = new Workbook();
|
|
527
|
-
// ... use workbook API
|
|
528
|
-
</script>
|
|
529
148
|
```
|
|
530
149
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
For a quick manual smoke test in a real browser (create/download/read XLSX, worksheet protection, etc.), use:
|
|
534
|
-
|
|
535
|
-
- [src/modules/excel/examples/browser-smoke.html](src/modules/excel/examples/browser-smoke.html)
|
|
536
|
-
|
|
537
|
-
Steps:
|
|
538
|
-
|
|
539
|
-
```bash
|
|
540
|
-
npm run build:browser:bundle
|
|
541
|
-
npx serve .
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
Then open `http://localhost:3000/src/modules/excel/examples/browser-smoke.html`.
|
|
545
|
-
|
|
546
|
-
### Browser-Specific Notes
|
|
547
|
-
|
|
548
|
-
- **PDF export is fully supported** in browsers with zero configuration
|
|
549
|
-
- **CSV operations are supported** using native RFC 4180 implementation
|
|
550
|
-
- Use `await workbook.readCsv(input)` to read CSV
|
|
551
|
-
- Use `workbook.writeCsv()` or `await workbook.writeCsvBuffer()` to write CSV
|
|
552
|
-
- Use `xlsx.load(arrayBuffer)` instead of `xlsx.readFile()`
|
|
553
|
-
- Use `xlsx.writeBuffer()` instead of `xlsx.writeFile()`
|
|
554
|
-
- Worksheet protection with passwords is fully supported (pure JS SHA-512)
|
|
555
|
-
|
|
556
|
-
## Utility Exports
|
|
557
|
-
|
|
558
|
-
The main entry also exports commonly useful utilities:
|
|
559
|
-
|
|
560
|
-
```typescript
|
|
561
|
-
import {
|
|
562
|
-
// Excel date conversion
|
|
563
|
-
dateToExcel, // JS Date -> Excel serial number
|
|
564
|
-
excelToDate, // Excel serial number -> JS Date
|
|
565
|
-
|
|
566
|
-
// Date parsing/formatting (high-performance, zero-dep)
|
|
567
|
-
DateParser, // Batch date parser with format auto-detection
|
|
568
|
-
DateFormatter, // Batch date formatter
|
|
569
|
-
|
|
570
|
-
// Binary utilities (cross-platform)
|
|
571
|
-
base64ToUint8Array,
|
|
572
|
-
uint8ArrayToBase64,
|
|
573
|
-
concatUint8Arrays,
|
|
574
|
-
toUint8Array,
|
|
575
|
-
stringToUint8Array,
|
|
576
|
-
uint8ArrayToString,
|
|
577
|
-
|
|
578
|
-
// XML utilities
|
|
579
|
-
xmlEncode,
|
|
580
|
-
xmlDecode,
|
|
581
|
-
xmlEncodeAttr,
|
|
582
|
-
validateXmlName,
|
|
583
|
-
|
|
584
|
-
// PDF export
|
|
585
|
-
pdf, // Simplest: pdf([["A", 1], ["B", 2]]) → Uint8Array
|
|
586
|
-
excelToPdf, // Workbook -> Uint8Array (Excel-to-PDF)
|
|
587
|
-
PageSizes, // Built-in page size definitions
|
|
588
|
-
PdfError, // Base PDF error
|
|
589
|
-
PdfRenderError, // Layout/rendering failures
|
|
590
|
-
PdfFontError, // Font parsing/embedding failures
|
|
591
|
-
PdfStructureError, // PDF structure assembly failures
|
|
592
|
-
isPdfError, // Type guard for PDF errors
|
|
593
|
-
|
|
594
|
-
// Error infrastructure
|
|
595
|
-
BaseError, // Base class for all library errors
|
|
596
|
-
ExcelError, // Base Excel error (instanceof checks)
|
|
597
|
-
toError, // Normalize unknown -> Error
|
|
598
|
-
errorToJSON, // Serialize error (with cause chain)
|
|
599
|
-
getErrorChain, // Get full error cause chain as array
|
|
600
|
-
getRootCause // Get deepest error in cause chain
|
|
601
|
-
} from "@cj-tech-master/excelts";
|
|
602
|
-
```
|
|
150
|
+
For older browsers without native `CompressionStream` API, ExcelTS automatically uses a built-in pure JavaScript DEFLATE implementation — no polyfills needed.
|
|
603
151
|
|
|
604
152
|
## Requirements
|
|
605
153
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
- **Node.js >= 22.0.0** (ES2020 native support)
|
|
609
|
-
|
|
610
|
-
### Browsers (No Polyfills Required)
|
|
611
|
-
|
|
612
|
-
- **Chrome >= 89** (March 2021)
|
|
613
|
-
- **Edge >= 89** (March 2021)
|
|
614
|
-
- **Firefox >= 102** (June 2022)
|
|
615
|
-
- **Safari >= 14.1** (April 2021)
|
|
616
|
-
- **Opera >= 75** (March 2021)
|
|
617
|
-
|
|
618
|
-
For older browsers without native `CompressionStream` API (Firefox < 113, Safari < 16.4), ExcelTS automatically uses a built-in pure JavaScript DEFLATE implementation - no configuration or polyfills needed.
|
|
154
|
+
- **Node.js >= 22.0.0**
|
|
619
155
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
- Worksheets
|
|
628
|
-
- Cells and Values
|
|
629
|
-
- Styling
|
|
630
|
-
- Formulas
|
|
631
|
-
- Data Validation
|
|
632
|
-
- Conditional Formatting
|
|
633
|
-
- File I/O
|
|
634
|
-
|
|
635
|
-
## License
|
|
636
|
-
|
|
637
|
-
MIT License
|
|
638
|
-
|
|
639
|
-
See LICENSE.
|
|
640
|
-
|
|
641
|
-
Third-party software notices and attributions are provided in THIRD_PARTY_NOTICES.md.
|
|
156
|
+
| Browser | Minimum Version |
|
|
157
|
+
| ------- | ------------------ |
|
|
158
|
+
| Chrome | 89+ (March 2021) |
|
|
159
|
+
| Edge | 89+ (March 2021) |
|
|
160
|
+
| Firefox | 102+ (June 2022) |
|
|
161
|
+
| Safari | 14.1+ (April 2021) |
|
|
162
|
+
| Opera | 75+ (March 2021) |
|
|
642
163
|
|
|
643
164
|
## Links
|
|
644
165
|
|
|
645
|
-
- [GitHub Repository](https://github.com/cjnoname/excelts)
|
|
646
|
-
- [Issue Tracker](https://github.com/cjnoname/excelts/issues)
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
166
|
+
- 🏠 [GitHub Repository](https://github.com/cjnoname/excelts)
|
|
167
|
+
- 🐛 [Issue Tracker](https://github.com/cjnoname/excelts/issues)
|
|
168
|
+
- 📋 [Changelog](CHANGELOG.md)
|
|
169
|
+
- 🔄 [Migration Guide](MIGRATION.md)
|
|
170
|
+
- 🗺️ [Roadmap](ROADMAP.md)
|
|
171
|
+
- 📄 [License (MIT)](LICENSE)
|
|
172
|
+
- 📦 [Third-Party Notices](THIRD_PARTY_NOTICES.md)
|